Sign in through GitHub

RailsCasts Pro episodes are now free!

Learn more or hide this

Aynul Habib's Profile

GitHub User: aynulhabib

Comments by Aynul Habib

Avatar

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

ruby
def category_name=(name)
  self.category = Category.find_or_create_by_name(name) if name.present?
end

try this

ruby
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!