In my users photo album page they see photos they have uploaded and each photo has a \'make default\' link on it.
When the user clicks make default
, then the id of
There is also this handy way to deal with it.
render :nothing => true
If you came from the photo_album page, you should be able to do:
redirect_to :back
Otherwise, you should be able to do a named route like:
redirect_to photo_album_path(photo.album_id) # or whatever the association key is
BTW, why do you have photo_albums mapping to photo_galleries? It's a lot less confusing if you named your resources and routes in a similiar manner. ie: if you wanted your route endpoints to use /photo_galleries you should name your resource PhotoGallery.
This is what you want:
redirect_to request.referrer
For further reference: http://en.wikipedia.org/wiki/HTTP_referer
redirect_to :back
worked for me but I want to see if this was the right choice
http://api.rubyonrails.org/files/actionpack/lib/action_controller/metal/redirecting_rb.html
In one project we used the session for temporary storage, because redirect_to :back
did not work for us.
We had an def new
where we set session[:return_to] = request.referer
in the def create
we added redirect_to session[:return_to]
.
I do not know anymore, why we could not use redirect_to :back
In Rails 5 it was introduced the function:
redirect_back(fallback_location: root_path)
It does redirect back whenever the HTTP_REFERER
is known. Otherwise it redirects to the fallback_location
.
The redirect_to :back
is deprecated and will be removed from Rails 5.1.