Search code examples
ruby-on-railsrubyback

Getting the value of :back in a view


So I'm trying to do something like this:

<% if :back == 'static_pages#game' %>
...do something...
<% if :back == 'static_pages#laugh' %>
...do something else...

I'm trying to get the URL where the action came from, and depending on where it came from, do something. It definitely does not work the way I'm doing it.


Solution

  • You can access the request referrer, for example with:

    <% if URI(request.referer).path == '/game' %>
    

    More info in: Rails 3 get request referrer