Forum: Ruby on Rails link_to or helper to generate a javascript:history.back() ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
oo00oo (Guest)
on 2006-01-17 16:06
(Received via mailing list)
Hello,

There is an link_to option or an helper that generate a link like :

<a href="javascript:history.back()">Back</a>

Thanks
Raghuraman Suraj (Guest)
on 2006-01-17 16:12
(Received via mailing list)
you can use link_to "Back", "javascript:histroy.back()"
Alex Y. (Guest)
on 2006-01-17 16:12
(Received via mailing list)
oo00oo wrote:
> Hello,
>
> There is an link_to option or an helper that generate a link like :
>
> <a href="javascript:history.back()">Back</a>

<%= link_to_function 'Back', 'history.back()' %>

Should do the trick...
oo00oo (Guest)
on 2006-01-17 16:33
(Received via mailing list)
Ok thanks, so no helper or option like :back => true
:)
Guest (Guest)
on 2006-01-17 21:30
oo00oo wrote:
> Ok thanks, so no helper or option like :back => true
> :)

Or you can add this to your ApplicationHelper.rb

def link_back
  return link_to_function 'Back', 'history.back()'
end

Then in your views:
<%= link_to_back %>
Kevin O. (Guest)
on 2006-01-17 23:57
Guest wrote:
> oo00oo wrote:
>> Ok thanks, so no helper or option like :back => true
>> :)
>
> Or you can add this to your ApplicationHelper.rb
>
> def link_back
>   return link_to_function 'Back', 'history.back()'
> end
>
> Then in your views:
> <%= link_to_back %>

You can also use 'redirect_to :back' which will send you back to the
referring page... not quite the same thing.

_Kevin
Guest (Guest)
on 2006-01-18 03:41
Guest wrote:
> oo00oo wrote:
>> Ok thanks, so no helper or option like :back => true
>> :)
>
> Or you can add this to your ApplicationHelper.rb
>
> def link_back
>   return link_to_function 'Back', 'history.back()'
> end
>
> Then in your views:
> <%= link_to_back %>

you mean
<%= link_back %>
This topic is locked and can not be replied to.