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

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.
C84750d2a27eb19a6aaa297be2db2bbc?d=identicon&s=25 Noah Stern (nfstern)
on 2005-12-07 01:33
I'm a newbie to Ruby on Rails and I have what I think is a fairly simple
question.

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 =>
"show",
      :id => service.user_id, :lastcontroller => "services", :lastaction
=> "list"
} %> - <%= service.user.firstname %> <%= service.user.lastname %>
</td>

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'])
  end

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.

Thx
nfstern
5c4ff5fdd4cae59a6aa4b516846ca5da?d=identicon&s=25 ncdram (Guest)
on 2005-12-07 08: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)'  %>

HTH,

Deepak
C84750d2a27eb19a6aaa297be2db2bbc?d=identicon&s=25 Noah Stern (nfstern)
on 2005-12-07 15: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.