Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Billy Boozer
6,486 PointsIncoming page url
This is a rails based site and I was wondering if there is a way to get the incoming page url. I need to know what the incoming page url is so that i can change the background of a landing page based on the url that the user is coming from.
Example: If user comes from www.example.com/1 then I need to show background1 on www.example.com/landingpage. If user comes from www.example.com/2 then I need to show background2 on www.example.com/landingpage. else if user comes from www.somerandompage.com then display default background on www.example.com/landingpage.
3 Answers
James Barnett
39,199 PointsYou can usually get a better response to these sorts of intermediate questions over on Stack Overflow.
In fact check this out: http://stackoverflow.com/questions/5819721/how-to-get-request-referrer-path
Sharon Walls
9,234 PointsYou could also use referral links to direct traffic to the right page.
Main page: http://www.mysite.com
Referral link: http://www.mysite.com/s?ref=2
Billy Boozer
6,486 PointsJames Barnett - the solution worked from stack for getting at the incoming url but I am now having a different issue.
This is what my code looks like:
-if URI(request.referer).path == '/some-page'
%p some content
-elsif URI(request.referer).path == '/some-other-page'
%p some other content
-else
%p The default content
So my problem now is that if I am coming to this page from anything other than '/some-page' || '/some-other-page' I get this error: bad URI(is not URI?):
How would you set a default state for this page? I also tried this:
-elsif URI(request.referer).path != '/some-page' || '/some-other-page'