Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Singular form problem

#3390

Hi,

I have a model with a user and many of his drives.

class User < ActiveRecord::Base

has_many :drives

end

class Drive < ActiveRecord:: Base

belongs_to :user

end

Now when I want to add another drive to the user like so:

drive = Drive.new() # ... user = user.find(x) user.drives << drive

This will create this error:

NameError: uninitialized constant User::Drife

      from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/

dependencies.rb:105:in const_missing'

      from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/ba

se.rb:2204:in compute_type'

      from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/

core_ext/kernel/reporting.rb:11:in silence_warnings'

      from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/ba

se.rb:2200:in compute_type'

      from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/re

flection.rb:156:in send'

      from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/re

flection.rb:156:in klass'

      from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/re

flection.rb:187:in quoted_table_name'

      from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/as

sociations/has_many_association.rb:96:in construct_sql'

      from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/as

sociations/association_collection.rb:21:in initialize'

      from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/as

sociations.rb:1277:in new'

      from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/as

sociations.rb:1277:in drives'

      from (irb):3

Reported by coffeeaddict_nl · October 18th, 2009 @ 07:36 AM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Ben Marini
    Ben Marini

    This is an inflection issue that can be solved by putting the following in config/initializers/inflections.rb:

    ActiveSupport::Inflector.inflections do |inflect|
      inflect.irregular 'drive', 'drives'
    end
    

    October 19th, 2009 @ 02:21 AM

  2. Ryan Bigg
    Ryan Bigg
    • State changed from new to invalid

    Follow Ben's advice.

    May 23rd, 2010 @ 07:05 AM