I want to start using the function first_or_create, which I found in the ActiveRecord API and in the guide at http://guides.rubyonrails.org/active_record_querying.html#find-or-build-a-new-object . However, Rails pretends not to recognize this function:
irb(main):017:0> EoWord.where("id = 110")
=> [#<EoWord id: 110, word: "abatino", wordtype: "substantivo", topic: "pregado, homo">]
irb(main):018:0> EoWord.where("word = 'abatino'").first_or_create
NoMethodError: undefined method `first_or_create' for #<ActiveRecord::Relation:0x1ccf578>
from E:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/relation.rb:374:in `method_missing'
from (irb):18
from E:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
from E:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
from E:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I’m running Rails 3.0.7 under Windows. Your help is much appreciated!
To answer your question: yes, this method is undefined in Rails 3.0.7.
This method only exists in Rails 3.2.1, according to APIDock’s documentation. You’ll need to upgrade your version of Rails to get it.