This problem is related to this question: Hashing an IP for saving
I have a model called Post. I have to pass in the IP address during post creation. I was told not to override the initialize(). So I used a factory method as suggested here: how to override new method for a rails model:
#Post.rb model
def self.new_with_ip(ip, attributes={})
self.new(attributes['one_day_id'] = do_some_conversion_on(ip))
end
However this does not get invoked, because Post is nested within a Discussion, and the nested form will not call this factory method. How can I make the form to invoke this instead of the traditional Post.new()
?