简体   繁体   中英

rails - redirect back unless previous page was artist page

I'd like to redirect back to the previous page, UNLESS the previous page was my 'artist' controller's 'show' action.

So I guess it would look something like:

if *previous page was artist show*
  redirect_to [track.artist, track]
else
  redirect_to :back
end

My question is - how do I test if the previous page was my artist controller's show action..?

Perhaps request.referer is what you're looking for? Then you can say something like:

if request.referer == artist_url(track.artist)
  redirect_to [track.artist, track]
else
  redirect_to :back
end

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM