Trying to figure out proper syntax for URLHelper for HTTP Referer

I am trying to add a condition so a “back” button does not appear if
the user arrived at the current page directly from a link offsite
(eg., a link from a tweet). I do want the button to appear if the user
arrived at the page from another page on our site:

From what I have read this seems like where I would use
url_options(ActionView::Helpers::URLHelper. The code below does not
work and I am uncertain why. Am I barking up the right tree or not
even in the ballpark?

  • <% unless request.env["HTTP_REFERER"] is not set or is blank %><%= link_to image_tag("/images/icons/ mico_back.png"), :action=>"results_bounce" %><% end %>
  • On 22 Mar 2011, at 05:42, “sol.manager” [email protected] wrote:

    link_to image_tag("/images/icons/
    mico_back.png"), :action=>“results_bounce” %><% end %>

    “is not set or is blank” isn’t Rails code – it’s just English. I preume
    you’re getting a runtime error on this line?

    Rails provides a #blank? method on objects that returns true if they are
    nil or empty. So you could try:

    unless request.env[“HTTP_REFERER”].blank?

    As an aside, when you’re posting about something like this, it’s helpful
    for us to see the actual error message that Ruby gave you, rather than
    just posting “it does not work”.

    Thanks,
    Chris

    Thank your for input. The error message was “syntax error, unexpected
    tIDENTIFIER, expecting kTHEN or ‘:’ or ‘\n’ or ‘;’
    …request.env[“HTTP_REFERER”] is not set or is blank ; _erbout…”

    It also looks like your correction did the trick. Thank you.

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs