rails - redirect back unless previous page was artist page

主宰稳场 提交于 2019-12-23 01:24:30

问题


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..?


回答1:


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


来源:https://stackoverflow.com/questions/4877093/rails-redirect-back-unless-previous-page-was-artist-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!