Ruby on rails redirect_to (: back) not working

Following some code in the Agile Web Development book, this method redirects back to the last page viewed using redirect_to (: back), however, when I do this, it just goes back to the page it was on.

What is the best way to get the desired result to work? Am I doing something wrong? My code is:

def update
@user = current_user
if @user.update_attributes(params[:user])
  flash[:notice] = "Successfully updated profile."
  redirect_to(:back)
else
  render :action => 'edit'
end
end
+3
source share
2 answers

I think it behaves as expected :

: back - Return to the page on which the request was sent. Useful for forms that run from multiple places.

+8
source

, ? , , - "", . ,: ( ). , ?

, -

redirect_to user_path(@user)
+1

Source: https://habr.com/ru/post/1715652/


All Articles