I am on an old version of Rails (3.0.5) and can’t upgrade right now. When I try to use assign_attributes on a model I get the error that the method is not found as below
I searched for the method in the classes where update_attributes is defined but indeed I couldn’t find assign_attributes defined in any of the gems. From the history of the method in the docs I understand it was created in 2.3.8 so I would think the method would be there in 3.0.5.
Any thoughts on why my ActiveRecord 3.0.5 gem doesn’t have this method defined?
Ryan-
since I see this a lot on the lists, it would be great if there were some easy place to see which versions of rails have security alerts against them. I know there’s this list here on rubygems https://rubygems.org/gems/rails/versions but it doesn’t show which ones are insecure.
is that information easily found without having to dig through the security alerts?
You need to download a proper IDE my friend, like RubyMine (which I love, but there are others)
Specifically, you need to learn how to use the “Go to Declaration” feature of your IDE, which can give you that answer and take you directly to the part of ActiveRecord where that might be defined.
I actually use RubyMine and Command-B takes you to the declaration of function but since there is no declaration it tells me so. The same command takes me to the declaration of update_attributes when I try it on that and there is no assign_attributes function that I can find in 3.0.5.
Thanks for any pointers on why this function is not there in 3.0.5.
I have temporarily solved the problem (till I upgrade) with the following code in one of my libraries
class ActiveRecord::Base
def assign_attributes(attributes)
attributes.each_pair { |k, v| send(“#{k}=”, v) if respond_to?(“#{k}=”) } if attributes
end
end
If you see any issue with this in 3.0.5 then please provide feedback - seems to work ok. I got this code from a posting in one of the forums.
indeed… sorry I just get in the habit of helping newbies who do would do well to learn more advanced introspection/debegging techniques. My bad.
Maybe your method is defined as delegate :x, :to => :y ? I hate that those don’t work with Go-To-Declaration – really drives me nuts
If you still can’t find it, open up console, replace the object you are trying to introspect, and try @foo.method(:assign_attributes).source_location – that should tell you exactly where it is defined.