I have a User model, and I am hoping to have different pages to edit their info so that I don't have everything on edit.html.erb
So far I have created views for page_content.html.erb
and donation_options.html.erb
which have my forms on them. Both work as intended and successfully update my User, but after submitting the form I am redirected the User root, which is show.html.erb
. I would like to set it up so that the user stays on the current page after updating their profile. I am not sure if I need to edit my UsersController
, or create a new controller, or take a different approach.
Here's an example of my form:
<%= form_for @user do |f| %>
<!--Some inputs-->
<div class="actions">
<%= f.submit 'Update', :class => "btn btn-primary" %>
<!--After submitting, I'm taken to /users/:id/. I'd like to stay on /users/:id/current_view-->
</div>
<% end %>
If you already have a UsersController
you should set something up comparable to this:
Class UsersController < ApplicationController
def update
@user = User.find(params[:id])
if @user.update(user_params)
redirect_to your_path_here
end
end
end
I am not sure exactly what your UsersController
looks like, but that should give you an idea. After a user is updated, use redirect_to
with your path you would like the User sent to. You may also use redirect_to :back
if you are looking to redirect back to the current page you are on.
Please see this existing SO post .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.