I setup a User model with restful_authentication
and then have a Profile model that belongs to it. I've been using fields_for
to combine the fields for editing a User and that user's profile into the User edit view.
I'd like to be able to set a few of the fields to use the in_place_editing
plugin on the User show view. It works fine on the User table fields following the example given
users_controller.rb
in_place_edit_for :user, :email
/views/users/show.html.erb
<%= in_place_editor_field :user, :email %>
but I can't figure out how to properly write the controller or the in_place_editor_field
bit on the view for any field that I access on the edit view via:
<% fields_for @up do |profile_fields| %>
<%= profile_fields.text_field :status %>
<% end %>
in the users_controller (for clarity):
def edit
@user = User.find(params[:id])
@up = @user.profile
end
How do I create the symbols for something like :user.profile, :status
for the users_controller and /views/users/show.html.erb?
Thanks for all help.
I use the in_place_editor helper tag. Wrap the stuff you want to edit in a span/div, give it a unique id and reference that in the in_place_editor tag.
The magic is the :set_user_email - it's an auto generated method in your controller that is created when you use in_place_edit_for in the controller on a model and its attribute(s).
I've included a way to allow for editing on all fields of a model but you may want to limit it to a few of the model attributes.
Depending on how you have the controller setup you may need to set protect_from_forgery to exclude the set action. Just so your aware - this will remove csrf validations on post methods from the in-place edit fields.
EDIT
This Question handles how to include the authenticity token.