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.
Related Posts
Google Criticized for Privacy Issues
Ian ‘Hixie’ Hickson, a prominent figure in the Flutter community, has left Google. Despite not being as public as other contributors, …
Llama 2 avoids errors by staying quiet, GPT-4 gives long, if useless, samples
The article discusses a study conducted by computer scientists at the University of California San Diego on the reliability and robustness of large …
NoMethodError (undefined method `finder') with Engines and Rails 2.2
I was getting this error with Rails 2.2 when using ActionMailer.
NoMethodError (undefined method `finder’ for #ActionView::Base:0x34146fc)
It …
