Rails 2.2 & Inflector

If you have recently updated to Rails 2.2.2, you may encounter this error when you want to start your application:

/.gem/ruby/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:445:in
`load_missing_constant': uninitialized constant Inflector (NameError)

As I learned from Paul’s post usage of Inflector class is changed a bit. You can see the difference when you compare the inflections.rb files. Path of the file is yourApp/config/initializers/inflections.rb

inflections.rb (Rails 2.1.0)

 Inflector.inflections do |inflect|
  .
  .
  .
 end

inflections.rb (Rails 2.2.2)

 ActiveSupport::Inflector.inflections do |inflect|
  .
  .
  .
 end

In my situation changing Inflector to ActiveSupport::Inflector was enough to solve the problem.

How to check if a div exists in rjs?

<body>
   <div id='main'>
      Main Div
   </div>
</body>

render :update do |page|
   page << "if ($('main')){"
   page.replace_html 'main', :inline => 'Here it is'
   page << "}"
end

This ruby code checks if there is a DOM object that its id = “main”.
If there is then changes its content to “Here it is”, if there is not do nothing.