Ruby on Rails: Using a different controller with in_place_editor_field

I don’t know why this took a while to figure out, but it did. If you are using the stock Rails in_place_editor_field, you know it looks like this in the controller:

in_place_edit_for :user, :name

And like this in the view:

<%= in_place_editor_field :user, :name %>

This works fine so long as you’re rendering from the users controller. But, what if this view is a partial inside a different controller’s view? In that case, what gets called is not “/users/set_user_name” but “/othercontroller/set_user_name”. And, of course, it fails because there is no method (dynamic or otherwise) like that there.

The solution is easy, but the documentation isn’t helpful. You need to alter the view to be like this:

<%= in_place_editor_field :user, :name, {}, :url=>{:controller=>'users', :action=>'set_user_name', :id=>user.id}} %>