Forum: Ruby on Rails Inflections

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
76d07ac70a63a21c650419fbb77de62f?d=identicon&s=25 stuart.coyle (Guest)
on 2008-10-08 02:52
(Received via mailing list)
I'm having difficulty getting inflections to work properly.
I have put this into environment inflection.rb :

ActiveSupport::Inflector.inflections do |inflect|
  inflect.plural 'criterion', 'criteria'
  inflect.singular 'criteria', 'criterion'
end

I have a habtm relationship between component_types and criteria with
tables called
component_types, criteria and the join table component_types_criteria

But when I do this...
>> c = Criterion.new
=> #<Criterion id: nil, question: nil, notes: nil, result_type_id:
nil, created_at: nil, updated_at: nil>
>> c.save
=> true
>> d = ComponentType.new
=> #<ComponentType id: nil, name: nil, manufacturer: nil, description:
nil, created_at: nil, updated_at: nil>
>> d.save
=> true
>> d.criteria << c
NameError: uninitialized constant ComponentType::Criterium
  from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/
active_support/dependencies.rb:493:in `const_missing'
  from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.1/lib/active_record/
base.rb:1914:in `compute_type'
  from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.1/lib/active_record/
reflection.rb:129:in `send'
  from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.1/lib/active_record/
reflection.rb:129:in `klass'
  from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.1/lib/active_record/
reflection.rb:137:in `quoted_table_name'
  from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.1/lib/active_record/
associations/has_and_belongs_to_many_association.rb:80:in
`construct_sql'
  from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.1/lib/active_record/
associations/association_collection.rb:8:in `initialize'
  from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.1/lib/active_record/
associations.rb:1135:in `new'
  from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.1/lib/active_record/
associations.rb:1135:in `criteria'
  from (irb):8
>>

I get a NameError, apparently ActiveRecord is looking for the singular
of criteria which it thinks is criterium. Active Record is bad at
latin, methinks.

Any clues? Or do I just have to refactor and rename the Criterion
model to Criterium?
76d07ac70a63a21c650419fbb77de62f?d=identicon&s=25 stuart.coyle (Guest)
on 2008-10-08 03:08
(Received via mailing list)
And I solved it myself...
I have to put the capitalized versions of the words in the
inflections, or rather make them a case insensitive regex!

Apologies for the noise.
This topic is locked and can not be replied to.