This project is archived and is in readonly mode.

#3390 ✓invalid
coffeeaddict_nl

Singular form problem

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

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

Comments and changes to this ticket

  • Ben Marini

    Ben Marini October 19th, 2009 @ 02:21 AM

    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
    
  • Ryan Bigg

    Ryan Bigg May 23rd, 2010 @ 07:05 AM

    • State changed from “new” to “invalid”

    Follow Ben's advice.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Tags

Pages