I have 2 actions - Edit and Update. Form in Edit submits the values to Update action. When saving a model fails I render edit teplate, where user sees errors and fields are prepopulated with what he filled before. There's a huge but for me - in URL panel in user's browser there's /user/update, even when (and because) I rendered edit template. Can I somehow change that with passing some parameters to render method in update action? I don't want the user to see that there's any (update) action aside of edit. Is it possible?
Here is the third way around this:
In your routes.rb
resources :users
match 'users/:id/edit' => 'users#update', :via => :put, :as => :put_user
In your view (edit.html.erb for example)
<%= form_for @user, :url => put_user_path do |f| %>
...
<% end %>
In your controller (users_controller.rb for example)
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
...
else
render 'edit'
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With