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
=> trued = ComponentType.new
=> #<ComponentType id: nil, name: nil, manufacturer: nil, description:
nil, created_at: nil, updated_at: nil>d.save
=> trued.criteria << c
NameError: uninitialized constant ComponentType::Criterium
from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/
active_support/dependencies.rb:493:inconst_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:insend' 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:inquoted_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:ininitialize' 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?