I’m working on a simple app that requires me to redirect to a show action after the update action.
I have this route for show.
match '/user/:fullname' => 'items#show'
Which gives me this controller.
@user = User.find_by_fullname(params[:fullname])
However, after the update method of user,
def update
if @user.update_attributes(params[:user])
format.html { redirect_to @user } # Don't need to pass parameters here.
else
format.html { render action: 'edit' }
end
end
It redirects me to the original format of show action which is:
sampleapp.dev/users/1
How can I redirect to show action using the format I specified in the routes.rb which is by fullname?
sampleapp.dev/users/johndoe
Change this line to:
then change your redirect to: