Upgrading my application - 2.3.5 to 3.2

Hello everybody…

i was trying update my application from 2.3.5 (yes… i know, very
old) to 3.2.

as we know, many changes occurred during that time and i don’t know if
this ploblem is a know problem or other rule of pluralization… well
i really don’t know how to solve this.

two models

Class Department < ActiveRecord::Base

has_many :waves

end

Class Wave < ActiveRecord::Base

belongs_to :department

end

Department.find(x).waves

explode this…

uninitialized constant Department::Wafe

/Users/murilomonteiro/.rvm/gems/[email protected]/gems/
activerecord-3.2.0/lib/active_record/inheritance.rb:119:in
compute_type' /Users/murilomonteiro/.rvm/gems/[email protected]/ gems/activerecord-3.2.0/lib/active_record/reflection.rb:172:inklass’
/Users/murilomonteiro/.rvm/gems/[email protected]/
gems/activerecord-3.2.0/lib/active_record/associations/association.rb:
117:in klass' /Users/murilomonteiro/.rvm/gems/[email protected]/ gems/activerecord-3.2.0/lib/active_record/associations/association.rb: 165:infind_target?’
/Users/murilomonteiro/.rvm/gems/[email protected]/
gems/activerecord-3.2.0/lib/active_record/associations/
collection_association.rb:332:in load_target' /Users/murilomonteiro/.rvm/gems/[email protected]/ gems/activerecord-3.2.0/lib/active_record/associations/ collection_proxy.rb:44:inload_target’
/Users/murilomonteiro/.rvm/gems/[email protected]/
gems/activerecord-3.2.0/lib/active_record/associations/
collection_proxy.rb:88:in method_missing' /Users/murilomonteiro/.rvm/gems/[email protected]/ gems/hirb-0.6.0/lib/hirb/formatter.rb:87:inblock in
determine_output_class’
/Users/murilomonteiro/.rvm/gems/[email protected]/
gems/hirb-0.6.0/lib/hirb/formatter.rb:87:in each' /Users/murilomonteiro/.rvm/gems/[email protected]/ gems/hirb-0.6.0/lib/hirb/formatter.rb:87:inany?’
/Users/murilomonteiro/.rvm/gems/[email protected]/
gems/hirb-0.6.0/lib/hirb/formatter.rb:87:in determine_output_class' /Users/murilomonteiro/.rvm/gems/[email protected]/ gems/hirb-0.6.0/lib/hirb/formatter.rb:53:informat_output’
/Users/murilomonteiro/.rvm/gems/[email protected]/
gems/hirb-0.6.0/lib/hirb/view.rb:204:in render_output' /Users/murilomonteiro/.rvm/gems/[email protected]/ gems/hirb-0.6.0/lib/hirb/view.rb:123:inview_output’
/Users/murilomonteiro/.rvm/gems/[email protected]/
gems/hirb-0.6.0/lib/hirb/view.rb:200:in view_or_page_output' /Users/murilomonteiro/.rvm/gems/[email protected]/ gems/hirb-0.6.0/lib/hirb/view.rb:186:inoutput_value’
/Users/murilomonteiro/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/
irb.rb:160:in block (2 levels) in eval_input' /Users/murilomonteiro/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/ irb.rb:273:insignal_status’
/Users/murilomonteiro/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/
irb.rb:156:in block in eval_input' /Users/murilomonteiro/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/ ruby-lex.rb:243:inblock (2 levels) in each_top_level_statement’
/Users/murilomonteiro/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/
ruby-lex.rb:229:in loop' /Users/murilomonteiro/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/ ruby-lex.rb:229:inblock in each_top_level_statement’
/Users/murilomonteiro/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/
ruby-lex.rb:228:in catch' /Users/murilomonteiro/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/ ruby-lex.rb:228:ineach_top_level_statement’
/Users/murilomonteiro/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/
irb.rb:155:in eval_input' /Users/murilomonteiro/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/ irb.rb:70:inblock in start’

i can find Wave.find(x).department.

why of this? uninitialized constant Department::Wafe

Thanks in advance for answers…

On Jan 23, 3:10am, Murilo Urban M. [email protected]
wrote:

i can find Wave.find(x).department.

why of this? uninitialized constant Department::Wafe

I think the inflection rules changed somewhere around 3.0, so when
rails tries to depluralize :waves, it gets ‘wafe’ and so looks for a
class of that name.

You should be able to override that inflection rule by doing something
like

ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular ‘wave’, ‘waves’
end

in an initializer

Fred

On Mon, Jan 23, 2012 at 6:02 PM, Frederick C. <
[email protected]> wrote:

in an initializer

To add more to what Fred said, you should already have an initializer
which is specifically for this purpose, look for
config/initializers/inflections.rb file

Chirag
http://sumeruonrails.com

On Mon, Jan 23, 2012 at 4:10 AM, Murilo Urban M. <
[email protected]> wrote:

end
/Users/murilomonteiro/.rvm/gems/[email protected]/
/Users/murilomonteiro/.rvm/gems/[email protected]/
/Users/murilomonteiro/.rvm/gems/[email protected]/
gems/hirb-0.6.0/lib/hirb/view.rb:200:in view_or_page_output' /Users/murilomonteiro/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/ irb.rb:70:inblock in start’

i can find Wave.find(x).department.

why of this? uninitialized constant Department::Wafe

Thanks in advance for answers…

Root cause is probably related to:

1.9.3p0 :002 > “Waves”.singularize
=> “Wafe”

Fix that first in config/initializers/inflections.rb

When the problem persists, we can look further.

HTH,

Peter

Thanks Fred, Chirag and Peter.

I wrote the following code inside the inflections:

ActiveSupport::Inflector.
inflections do |inflect|
inflect.irregular ‘wave’, ‘waves’
end

and “waves”.singularize return “waves”

this was the cause of the problem.

Thnks again.

2012/1/23 Peter V. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs