When I create a user in my database, it also creates a unique identifier string.
In my routes, I have:
match '/users/:unique_identifer', :to => 'users#show'
This part is working fine. When I go to /users/xyz, it brings me to the show action for the appropriate user.
However, when I try to update the user record, it redirect me back to /users/SOMENUMBER where SOMENUMBER is the user’s ID. This causes an error since the show action in the controller has:
def show
@user = User.find_by_unique_identifier(params[:unique_identifer])
end
In other words, the show action is now only looking up the user by their unique identifier and not the user id.
The update action is as follows:
def update
@user = User.find_by_unique_identifier(params[:unique_identifer])
if @user == current_user && @user.update_attributes(params[:user])
redirect_to @user
else
redirect_to @user
end
end
How do I get the update action to redirect to the user’s show action but with the appropriate link (/users/unique_identifier) instead of /users/ID?
Try this
or