Useful as usual.
Good to see you still make simple Railscast suited also for Rails-beginners.
Wanted to learn a bit more about the 'request' method/object and what you can do with it. But the docs don't have much to say about it. Do you know where it is defined and what else you can do with it?
Hi Ryan,
Thanks for your Railscasts. I am not sure if its a sign of how sad my life is at the moment but I look forward to seeing the new Railscast every monday. I used to get Crash magazine as a kid and my little heart would beat faster when I remembered that was the day that it was in the shops. Get the same feeling revery monday when I see the RSS feed, I am a newbie and much goes over my head but heh. Do I need help?
Well done & thanks.
I define a redirect_back_or_default method that uses redirect_to(:back) and ActionController::RedirectBackError: http://pastie.textmate.org/private/2pc1znldyvmbencfpvf0g
…since redirect_to(:back) will raise if there is no refer(r)er. I don't think you said explicitly.
Trying the link again: <a href="http://pastie.textmate.org/private/2pc1znldyvmbencfpvf0g">http://pastie.textmate.org/private/2pc1znldyvmbencfpvf0g</a>
Wonderful screencast. This is one of those little things everyone needs to do but not everyone knows the best approach. Thanks for continuing to do the quick simple tips between the heavy hitter subjects!
@Richard: Your not alone, its about the only thing to look forward to on Monday! :)
@Per Velschow, the request object is documented under ActionController:AbstractRequest which you can find here:
http://api.rubyonrails.com/classes/ActionController/AbstractRequest.html#M000808
The "env" variables (like I'm using here) can change per request. Try tossing this in a view to see the options:
<%= debug request.env %>
@Henrik, Good point! I forgot to mention the :back option will raise an exception if the referer isn't specified.
Good episode.
What about the scenario of linking to an edit form, i.e. /products/5/edit, and after submitting it goes to /products/5/update. Redirecting back from here goes back to the edit form. I've used a few different solutions (check points, passing original_uri GET parameters, etc)
Anyone else have this issue or want to share a solution?
@Austin, You can use the referer technique for this, but you'll have to capture it when entering the form instead of when the form is submitted. Something like this:
<%= hidden_field_tag :referer, (params[:referer] || request.env['HTTP_REFERER']) %>
Then you can use params[:referer] in the controller to redirect back.
In version 2.2, there's a new 'referrer' method in request.rb. This means you can simply use "request.referrer" in the controller.
Another way to attack this problem is to have the User's URL store their previous route.
It's not ideal for every case, but if you have a lot of this stuff going on on your site (especially with polymorphic-like views), it can be handy as you don't have to manually keep tabs on the referer.
I've been playing around with putting this into a plugin for the last few weeks at:
http://github.com/toothygoose/historic_routes/tree/master
It's not totally weaponized yet, but I think the concept is sound.
Since the referrer is unreliable (I always turn off sending it in my browsers), I'd suggest storing request.request_uri in session instead and using that when necessary.
http://pastie.org/292092
@AC, that's a cool idea. But don't you need to use an after_filter instead of a before_filter so it resets at the end of the request instead of the beginning?
Also you can make exceptions using the skip_after_filter method in the controller.
please also mention the most obviouse choise:
link_to 'Continue', :back
Ryan,
This has nothing to do with this Railscast, but I have a suggestion for a Railscast topic.
Would you please do a Railscast on the usage of html frames w/in Rails, particularly if the contents of those frames are dynamic. I'm not sure that this is even possible, but I would love to know for sure.
Thanks,
kevin
What about the scenario of linking to an edit form, i.e. /products/5/edit, and after submitting it goes to /products/5/update. Redirecting back from here goes back to the edit form. I've used a few different solutions (check points, passing original_uri GET parameters, etc)
Wow, spammers are copying others comments. That's a new one.
I think I'll choose for not using the session, but have the browser keeping state by appending the continu shopping url to the show cart URL.
Thanks! A simple technique and a great tutorial.
We have to keep in mind that request.env['HTTP_REFERER'] doesn't exist on the test environments in case you're testing the redirect!
When using params with the redirect_to method be aware of the security implications. Check out my blog post and the "Response Splitting" post in the Rails weblog.
Using the helper method link_to with the :back option would be the best for displaying the "Continue shopping" link.
link_to('Continue shopping', :back)
This is better because it will link to the referrer if it is present or "javascript:history.back()" when there is no referrer.
I am trying to use the redirect_to :back from an action, but I am using restful_authentication, and the action requires the user to be logged in (I have a before_filter :login_required in the controller), so when I am already logged in the :back works fine, but when it redirects first to the login page, when it gets to the redirection in my action, it tries to go back to /session/new...
Is there any easy way to fix this?
@Ryan "But don't you need to use an after_filter instead of a before_filter so it resets at the end of the request instead of the beginning?"
Yes, must use a after_filter, that's exactly how I implement mine. Plus it keeps it from muddying up the controller.
Now this code will help me I my latest project.Thanks For posting it..
I was searching for information on Railscast, and google directed me to this page.
I used to get Crash magazine as a kid and my little heart would beat faster when I remembered that was the day that it was in the shops.
It is very nice coding. This coding will very beneficial for our sites because by this coding user can visit one page to another page.
Its really very helpful code that you shared thanx a lot for this.
Thanks for the post. Idea behind your post is interesting.i would like to read more from you.
Nice informative post thanks for sharing with us.
I used your code in my project. Your code is fully operational.
I think episode has really reduced the overhead of pressing back button to show the previous page.
Thanks for posting. Idea behind your post is interesting.i would like to read more from you.
I have bookmarked you page, hopefully you add some more codes for us to use.
Redirecting using your code is very easy. If you some more details about this then please share it with me.
Hi people,
Well I am new here and really enjoyed reading the article.
Thanks for sharing this great piece of information.Do keep us update with some more great articles.
I found your blog from google and read a few of your other posts. They are incredible. Please keep it up… have a nice day.
this information is very nice and activities post. I hope it will get more benefit to me.
I think this episode will really reduce the overhead of pressing back button again and again to redirect to the previous page. Thanks for sharing information.
the code contains lot of concepts and i thibk it will help in programming also.
This article gives the light in which we can observe the reality. this is very nice one and gives in depth information. thanks for this nice article.
Really appreciate this post. It’s hard to sort the good from the bad sometimes, but I think you’ve nailed it!
I read your post. It was amazing. Your thought process is wonderful. The way you tell about things is awesome. I always wait for your posts. They are inspiring and helpful. Thanks for sharing your information .
Resources like the one you mentioned here will be very useful for me!
thanks for this ..i was looking for it quite a long time now
Hey I just got through with the pages, I should say Pretty nice work done there.
Hey this is really nice information. I was looking for something similar like this. Thanks for this useful information.
It’s a fastidious and instructive article. Things are ordered wellspring. Get to bonk lot’s of thing which were not region to me.
I was often like to read such type of informative post,thanks for sharing it.
I agree with Netflix.The info here is really solid!
Good info and explanation as usual. Thanks for sharing the info.
It’s hard to find knowledgeable people on this topic, but you sound like you know what you’re talking about! Thanks
The code is really very useful for online marketing purpose.
What about the scenario of linking to an edit form, i.e. /products/5/edit, and after submitting it goes to /products/5/update. Redirecting back from here goes back to the edit form. I've used a few different solutions (check points, passing original_uri GET parameters, etc)
I was looking for such information for a long time and I am glad that I finally came here! Thanks for sharing the such information with us.
AMAZING! Great post! Thank you for sharing!
Are you coming out with any more codes anytime soon?
I love the code and I have bookmarked this page to come back if you have more codes later on.
Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful and beneficial to your readers.
Thank you for this useful information.I will share it with my friends.I have done bookmarked it.
This episode demonstrates a couple ways to redirect the user back to a previous page. Applying this to your site can help minimize the user's need to press the back button.
This is one of the best posts that I’ve ever seen; you may include some more ideas in the same theme. I’m still waiting for some interesting thoughts from your side in your next post.
It’s a fastidious and instructive article. Things are ordered wellspring. Get to bonk lot’s of thing which were not region to me.
Amazing..you really made my day & after reading this Surely..i ll twit this to my all friends to know more about this blog :)
Hey this is really nice information. I was looking for something similar like this. Thanks for this useful information.
hey buddy,this is one of the best posts that I’ve ever seen; you may include some more ideas in the same theme. I’m still waiting for some interesting thoughts from your side in your next post.
Awesome! Some really helpful information in there. Bookmarked. Excellent source.
Thanks for continuing to do the quick simple tips between the heavy hitter subjects!
<a href="http://ezinearticles.com/?Natural-Colon-Cleanse---The-Best-Natural-Colon-Cleanse-Method-That-Really-Works&id=2711200">colon cleanse</a>
Well I really like the ad and i think there is an immediate need of health awareness among youngsters, It’s a fastidious and instructive video. Things are ordered wellspring.
Thanks for sharing your thoughts with us.. they are really interesting.. I would like to read more from you.
Thank you for this useful information.I will share it with my friends.I have done bookmarked it.
Couldnt be written any better. Reading this post reminds me of my old room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thanks for sharing!
This is one of the best post that I have ever read. You have provided a great piece of information. I will definitely share it with my other friends. Keep up the good work, I would to stay in contact with your posts.
Would you please do a Railscast on the usage of html frames w/in Rails, particularly if the contents of those frames are dynamic. I'm not sure that this is even possible, but I would love to know for sure.
Would you please do a Railscast on the usage of html frames w/in Rails, particularly if the contents of those frames are dynamic. I'm not sure that this is even possible, but I would love to know for sure.
Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.
Absolutely fantastic posting! Lots of useful information and inspiration, both of which we all need! Thanks for the sharing information we will wait also for your new article keep posting.
I want to say that after reading your post I have found so many interesting thing in your blog and I really love that. Keep up the good work!
I was looking for such information for a long time and I am glad that I finally came here! Thanks for sharing the such information with us.
I have read a number of posts of yours, but this is the one that I like the most. So expecting some more ideas from your side. Thanks
Hey this is really nice information. I was looking for something similar like this. Thanks for this useful information.
I read lot post,but your post is one of the best in all,really interesting and informative,keep it up.thanks
Yeah, excellent info, thanks for the informative post and help.
Excellent post, glad you wrote this as it really got me thinking.
<a href="http://alanwattsbooks.blogspot.com/" >alan watts books</a> | <a href="http://facebookofsex.over-blog.com/" >facebooksex</a> | <a href="http://facebooksluts.over-blog.com/" >facebook sluts</a> | <a href="http://facebookwhores.over-blog.com/" >facebook whores</a>
Hey I m really appreciate after reading this blog. Please this type posting continue. I want to say I m very thankful to you for this.
Thanks, just the code I was searching for. I love google for bringing me here.
First time i have visit this site.I have read this blog,i noted that there are mostly good points which increase the importance of the blog.Nice work.Keep it up to write more good information.
Hi..Your post is amazing. From long time I search for this information. But I didn’t get right thing. Thanks to you I got stuff which I am looking for. I would like to read more from you.
nice post, a very informative and a great post provided i might add, i seriously want to take a moment here and thank you for providing your ideas related to the Independent Software Vendor. Keep posting.
Your posts are always very useful. Thanks for a link, its very helpful.
This years top searches <em class="field"><a target="_blank" id="finalhtmlcode" class="field-label-inline external-link" href="http://www.casinoonlinevip.it">casino online</a>
<em class="field"><a target="_blank" id="finalhtmlcode" class="field-label-inline external-link" href="http://www.online1poker.com">online 1 poker</a>
<em class="field"><a target="_blank" id="finalhtmlcode" class="field-label-inline external-link" href="http://www.casininio.com/roulette.html">roulette online</a> <em class="field"><a target="_blank" id="finalhtmlcode" class="field-label-inline external-link" href="http://www.casininio.com/blackjack.html">blackjack online</a><a target="_blank" id="finalhtmlcode" class="field-label-inline external-link" href="http://www.casininio.com/">migliori casino online italiani</a> <em class="field"><a target="_blank" id="finalhtmlcode" class="field-label-inline external-link" href="http://www.live4gambling.com">online casinos gambling guide</a></em></em></em></em></em>
<em class="field"><a target="_blank" id="finalhtmlcode" class="field-label-inline external-link" href="http://www.casininio.com/europa1.html"> europa casino </a> <a target="_blank" id="finalhtmlcode" class="field-label-inline external-link" href="http://www.casininio.com/spin-palace.html"> spin palace casino on line </a> <a target="_blank" id="finalhtmlcode" class="field-label-inline external-link" href="http://www.casininio.com/poker-online.html">poker online </a> <a target="_blank" id="finalhtmlcode" class="field-label-inline external-link" href="http://www.onlinecasinobaer.com">onlinecasinobaer</a> </a> <a target="_blank" id="finalhtmlcode" class="field-label-inline external-link" href="http://www.onlinecasinorsk.com"> casinorsk</a>
You can use the referer technique for this, but you'll have to capture it when entering the form instead of when the form is submitted.
Your post is amazing. From long time I search for this information. But I didn’t get right thing. Thanks to you I got stuff which I am looking for. I would like to read more from you.
I have read this blog,i noted that there are mostly good points which increase the importance of the blog.Nice work.Keep it up to write more good information.
Good information, though i think the design here could be better to each his own i guess.
Amazing post!
i would like to appreciate your information providing way.its great,and i like it lot.
Hey this is really nice information. I was looking for something similar like this. Thanks for this useful information.
I am already logged in the :back works fine, but when it redirects first to the login page, when it gets to the redirection in my action, it tries to go back to /session/new...
Is there any easy way to fix this?
Great Post as usual. The User can go back without pressing the Back Button.
I find it difficult to subscribe RSS feeds, bookmark this site anyway I have is a very useful and complete information.
Get the same feeling revery monday when I see the RSS feed, I am a newbie and much goes over my head but heh. Do I need help?
I'm interested in the topic of this post - What else can I read on this topic?
I really enjoyed your blog post. I bookmarked your page so I that can keep track of your future post.
Fantastic Read! Looking forward to more! Bookmarked the site and will be back again!
Thanks! This is truly fantastic stuff - thank you too your knowledge. We share the opinion on and I really enjoy reading your article. Web proliferation of new developments in the field of design and entrepreneurial spirit of people who have very beautiful and pleasing to be professional
I have always liked Outdoor movies, a child standing at the window, looked out from home to
the following. Will be able to see the staff busy figure, a huge white cloth has a child
hang up and soon will be able to see the movie.
Great post! I am just starting out in community management/marketing media and trying to learn how to do this source code - resources like this article are incredibly helpful.
Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it. My readers have about the same interets
Discount Wholesale Electronics, Wholesale Cell Phones, Electronic Gadgets and More from the Best Dropship Wholesaler
Wow! This can be one particular of the very best blogs I’ve ever occur across on this subject. Merely Magnificent
You wrote great Blog post. You have posted such a effectful article that it will really help me
Also you can make exceptions using the skip_after_filter method in the controller.
http://newsblogs.chicagotribune.com/afghan-war-blog/2009/08/heart-on-the-home-front.html






