redirect_to :back not reliable
Suppose you want to allow someone to make a comment and then return to the page they were on. An easy way to do this in Rails is to set the CommentsController method to redirect_to :back
def create
comment = Comment.new(params[:comment])
if comment.save
redirect_to :back
end
end
But beware! The trouble with this is that Firefox has an option to disable referrers, so you can’t rely upon the HTTP_REFERER being set.
So you could set up a session variable when you display your comment form, to later be used in the controller. The current url is found in request.path
<% session[:return_to] = request.path -%>
def create
comment = Comment.new(params[:comment])
if comment.save
redirect_to session[:return_to]
end
end
Sure, people can turn off session cookies, but if they do that then you have all sorts of other Rails problems to do with authenticity tokens and user authentication, so I think this is a fairly safe method.
Of course, an even better option is to add the comment by AJAX and avoid the need for a page refresh at all … but that can be the topic of a different blog post!

Different point of view from that post. Interesting to say the least.
Interesting post. I have made a twitter post about this. Others no doubt will like it like I did.
Sounds like some great advice. I would think that terrified is not 100% the best word to use in “Be terrified every day”, I think excited could also work there. Everything in the space is constantly changing and evolving, so hrsaccount designers have a new opportunity to potentially come up with something revolutionary every day. And it is kind of funny to read “Embrace Arial” written in Times New Roman font.
Great posting. I like this.
Thanks for sharing your tips.And it is kind of funny to read “Embrace Arial” written in Times New Roman font.
how to understand this code
I wonder if it is in the works for this type of thing to be programmed into disqus from the get-go?
nice post, thanks
wow i really found this to be interesting. thanks for sharing
This a spot on analogy made me chuckle.
exactly ! now a days many webmasters use ajax to avoid the page and give user a consistent feeling , and by the way many dont use firefox so for them HTTP_REFERER method will do
Thanks for sharing that interesting codes. That's really helpful.
Great blog.It is really informative article.The idea you sharing about CommentsController method gave me some food for thoughts.I am thinking of trying it now!Hope i will manage!Thank you for sharing your experience and teaching us.
Inventory Control
Wow a great posting. I like this. Thanks for sharing yours tips…..
So you could set up a session variable when you display your comment form, to later be used in the controller. The current url is found in request.path
Thanks and Regards
Thanks for sharing such an important tips with us. Great Article. looking for more tips.