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

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}} %>

2 responses to “Ruby on Rails: Using a different controller with in_place_editor_field”

  1. Thanks! It would be helpful if the plugin documentation was longer then two lines — this code really helps!

  2. […] working. The first problem was the InvalidAuthenticityToken and the second issue was that I use a different controller, but now it works […]

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