RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: aynulhabib
Just a heads up for those in Rails 4, I got stuck because of 1 thing:
the "find_or_create_by" method has been deprecated in rails 4
so instead of this
def category_name=(name) self.category = Category.find_or_create_by_name(name) if name.present? end
try this
def category_name=(name) self.category = Category.where(:name => name).first_or_create! end end
source: http://stackoverflow.com/a/3046645/4195073
Hope that helps someone!
Just a heads up for those in Rails 4, I got stuck because of 1 thing:
the "find_or_create_by" method has been deprecated in rails 4
so instead of this
try this
source: http://stackoverflow.com/a/3046645/4195073
Hope that helps someone!