Forum: Ruby on Rails Navigation - Link back to a calling controller/action

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Noah S. (Guest)
on 2005-12-07 02:33
I'm a newbie to Ruby on Rails and I have what I think is a fairly simple

I'm developing an application which lists Enterprise Services.  Each
Service has a User (actually a contact person) which I display with a
link to the Users show view.

I got this working from the Services List screen as follows:

<td width="25%">
  <%= link_to service.user.userid, { :controller => "users", :action =>
      :id => service.user_id, :lastcontroller => "services", :lastaction
=> "list"
} %> - <%= service.user.firstname %> <%= service.user.lastname %>

My problem is that I cannot figure out the syntax to get the back link
on the Users show screen working.

My users_controller.rb has this:
  def show
  	last_controller = @params['lastcontroller']
  	last_action = @params['lastaction']

    @user = User.find(@params['id'])

I tried variations of this in my show.rhtml and got errors.
<%= link_to 'Back', :controller => lastcontroller, :action => lastaction

Any suggestions would be greatly appreciated.

ncdram (Guest)
on 2005-12-07 09:04
(Received via mailing list)
Hey Noah,

Unless you do not really want to use JS, you could use:

<%= link_to 'Back', 'javascript:history.go(-1)'  %>


Noah S. (Guest)
on 2005-12-07 16:20
ncdram wrote:
> Hey Noah,
> Unless you do not really want to use JS, you could use:
> <%= link_to 'Back', 'javascript:history.go(-1)'  %>
> HTH,
> Deepak

Okay thanks Deepak.  I did eventually get it to work using 2 instance
variables @last_controller & @last_action.  However this only works when
you go 1 screen back.  If you do this sequence: List Services -> Show
User -> Edit User, it breaks trying to go back from Edit to Show.  I
finally decided that if the user wants to go back, they can click on the
back button on Firefox, so I disabled the back link.

I think your solution probably fixes that and I will try it when I get
into the office today.
This topic is locked and can not be replied to.