in_place_editor_field method in Ruby on Rails

I kept getting this error with attempting to use the Ruby on Rails in_place_editor_field method.

Called id for nil, which would mistakenly be 4—if you really wanted the id of nil, use object_id

It was driving me nuts! This method is supposed to attach some script.aculo.us javascript to some text, to allow the text to be edited by clicking on it. Not the nasty error above.

Much too much googling later returns of a solution…

“If you’re receiving this error while using the in_place_editor_field method, chances are you’re iterating through a list of objects and you’re passing the variables to the method incorrectly.

To fix this problem, set the current iteration as an instance variable and you should be fine.

For example:

<% for person in @people %>
<% @person = person %>
<%= in_place_editor_field :person, :name %>

Further explanation.

5 Responses to “in_place_editor_field method in Ruby on Rails”

  1. we eat bricks » Blog Archive » SEO Tip #1 : Use “Pretty Permalinks” with Apache mod_rewrite Says:

    [...] August 2006 « in_place_editor_field method in Ruby on Rails [...]

  2. Paul Welty Says:

    Thanks for the tip. It turns out this trick will work when the same thing breaks in a partial.

  3. Polymathic Says:

    In_place_editor with a collection in a partial in Ruby on Rails…

    It seems like it would take a lot of work to get the in_place_editor to work in a partial on a collection, but it does. (It took me a lot of time to figure this out, but maybe I’m just more than average dense.) (The best post to-date on this is a…

  4. Chris Says:

    Thanks for the tip. It saved me hours.

  5. Brady Says:

    Thanks for this! I had been having the exact same problem!

Leave a Reply