I have a model I named User, and I want use two different Views to edit it: the usual edit view and another view I called edit_profile.
I had no problem in creating routing, controller and views: I added edit_profile and update_profile views, and I added on routes.rb the line:
map.resources :users ,:member => {:edit_profile => :get, :update_profile => :put}
The problem is: when I submit the form in edit_profile and some error occur in some input fields, rails reload the edit_path page instead of edit_profile_path page !
This is the form on edit_profile.html.erb
form_for(:user, @user, :url => {:action => :update_profile}, :html => { :method => :put} ) do |f|
f.text_field :description
f.text_area :description
f.error_message_on :description
....
....
f.submit 'Update profile'
After clicking Update profile, if input errors occur I want to show edit_profile view instead of edit view
Where is the problem ?
Do You have some ideas ?
many thanks
Your controller’s action (the
editaction, I assume) will need to know whether it has been reached via the normaleditpage or theedit_profilepage. You can use a hidden field named, perhaps,profileto post a breadcrumb that will tell it that. By doing this, you can redirect conditionally based on the existence of aprofileparam.A cleaner way is to create a new action called
edit_profileand extract the editing code to a common method that is called from botheditandedit_profilelet the public methods handle any redirects.