About this blog

Hi folks, Jamie here.

I'm a web developer at the Ionic Business Systems.
I blog about web development, content management systems, design, user experience and anything else that comes to mind.

Feeds

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. September 10th, 2007 at 9:23 pm

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

  2. September 23rd, 2007 at 10:36 pm

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

  3. September 23rd, 2007 at 10:38 pm

    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

    October 15th, 2007 at 10:31 pm

    Thanks for the tip. It saved me hours.

  5. Brady

    August 15th, 2008 at 2:11 am

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

Leave a Reply