Polymathic

Digital transformation, higher education, innovation, technology, professional skills, management, and strategy


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 at we eat bricks.

Just add the usual in the controller (user_controller.rb):

in_place_edit_for :user, :name

And, of course, the method:

def edit
  @users = User.find(:all)
end

Then, in the main view (edit.rhtml):

<%= render :partial=>'user', :collection=>@users %>

Then, in the partial (_users.rhtml):

<%= in_place_editor_field :model, :column %>

At first, this won’t work. You will get an error that says “Called id for nil, which would mistakenly be 4 — if you really wanted the id of nil, use object_id” on the line containing the “in_place_editor_field”.

It turns out this is a bug, and there is a workaround. Just add this at the top of your partial:

<%- @user = user -%>

I hope this helps someone save some time.



6 responses to “In_place_editor with a collection in a partial in Ruby on Rails”

  1. Thanks for the mention:-)

    Looks like we both are exploring innards of Ruby on Rails. I’ll be sure to keep an eye on your blog.

    Best of luck!
    Jamie

  2. Thanks v much for this – saved me hours :):):)

  3. Thanks! This helped a LOT!

  4. Zaphod Beeblebrox Avatar
    Zaphod Beeblebrox

    I saved a lot of time !!! Thanks

  5. Anko Painting Avatar
    Anko Painting

    Thank you!!!!!!!!!!!

    This would have taken me ages to work out!

  6. Yes Yes!!!
    It rocks for me, saved me a lot of googling time, wonderfull !

Leave a Reply

Your email address will not be published. Required fields are marked *

About Me

Digital transformation, including agile and devops, across many industries, most recently in higher education. Designed and built the Emory faculty information system. Working in continuing education to improve and expand career-focused learning, esp. in workforce development. Expanding the role of innovation and entrepreneurship. Designed, built, and launched the Emory Center for Innovation.

Favorite sites

  • Daring Fireball

Favorite podcasts

  • Manager Tools

Newsletter

Newsletter