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 -- Posted via http://www.ruby-forum.com/.
N. C. Deepak Ramesh
2005-Dec-07 07:03 UTC
Re: Navigation - Link back to a calling controller/action
Hey Noah, Unless you do not really want to use JS, you could use: <%= link_to ''Back'', ''javascript:history.go(-1)'' %> HTH, Deepak Noah Stern wrote:> 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 >
Noah Stern
2005-Dec-07 14:20 UTC
Re: Navigation - Link back to a calling controller/action
ncdram wrote:> Hey Noah, > > Unless you do not really want to use JS, you could use: > > <%= link_to ''Back'', ''javascript:history.go(-1)'' %> > > HTH, > > DeepakOkay 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. -- Posted via http://www.ruby-forum.com/.