0

I have a method inside my controller which is called by Link_to which detects which user called the controller to render out a different view but I need to detect which individual link was pressed not just which user called the controller

tereško
  • 58,060
  • 25
  • 98
  • 150
arcanine
  • 1,933
  • 1
  • 15
  • 22
  • What do you mean, which link? They'll either route to different controllers/actions, or have a parameter indicating what differentiates the link from the others. Can you be more specific? – Dave Newton Nov 23 '11 at 20:26
  • I need them to point to the same action for example I want two buttons one that displays results which have the approved attribute as true and one which displays results which have the approved attribute as false, they both call the index action in the controller but I need a way to differentiate. basically how to pass that parameter you mentioned to the controller? – arcanine Nov 23 '11 at 20:29
  • so that on the controller I can read the parameter in and say if parameter == x then render this particular view – arcanine Nov 23 '11 at 20:30
  • Just add a parameter; not sure what the issue is. See [this SO post](http://stackoverflow.com/questions/2695538/add-querystring-parameters-to-link-to). – Dave Newton Nov 23 '11 at 20:30
  • would you mind providing an example using this: <%= link_to 'View Previous Absences', :controller=> "absences", :action=>"index" %> I don't know if it's different because I'm not using a path – arcanine Nov 23 '11 at 20:32
  • What happened when you tried? – Dave Newton Nov 23 '11 at 20:33
  • like this? <%= link_to 'View Previous Absences', absences_path(:completed => '1') %> if so how do I access the completed parameter on the other side? – arcanine Nov 23 '11 at 20:40
  • Perfect, think I've got it all together, thank you very much – arcanine Nov 23 '11 at 20:53
  • Cool; glad you worked it out :) – Dave Newton Nov 23 '11 at 20:57

1 Answers1

1

If it is the same controller/action do this.

 link_to 'home', root_path(:link => 'one')

then for the next link

 link_to 'home', root_path(:link => 'two')

now in your controller

params[:link] 

will give the link name

drhenner
  • 2,200
  • 18
  • 23