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.
Leave a Reply