sol.manager
2011-Mar-22 05:42 UTC
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? <li><% unless request.env["HTTP_REFERER"] is not set or is blank %><%link_to image_tag("/images/icons/ mico_back.png"), :action=>"results_bounce" %><% end %></li> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Chris Mear
2011-Mar-22 06:14 UTC
Re: Trying to figure out proper syntax for URLHelper for HTTP Referer
On 22 Mar 2011, at 05:42, "sol.manager" <sol.manager-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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? > <li><% unless request.env["HTTP_REFERER"] is not set or is blank %><%> link_to image_tag("/images/icons/ > mico_back.png"), :action=>"results_bounce" %><% end %></li>"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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
sol.manager
2011-Mar-22 13:20 UTC
Re: Trying to figure out proper syntax for URLHelper for HTTP Referer
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. On Mar 22, 2:14 am, Chris Mear <chrism...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 22 Mar 2011, at 05:42, "sol.manager" <sol.mana...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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? > > <li><% unless request.env["HTTP_REFERER"] is not set or is blank %><%> > link_to image_tag("/images/icons/ > > mico_back.png"), :action=>"results_bounce" %><% end %></li> > > "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-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.