38

I know this is probably a pretty simple concept. I am trying to create a link to a controller and action. For example I have a link in my layout file to update a record when a link is clicked, so I need to be able to link to the controller and action. How would I accomplish this?

Jason Yost
  • 4,757
  • 7
  • 41
  • 64
  • You use link_to to link to an action on a controller. You need to provide more information to get the full answer. Could you provide the name of your controller and the action you require? – Gazler Apr 09 '11 at 19:05

3 Answers3

57
link_to "Label", :controller => :my_controller, :action => :index

See url_for.

Jakub Hampl
  • 38,520
  • 9
  • 73
  • 103
9

Also with CSS:

<%= link_to "Purchase", { :controller => :transactions, :action => :purchase }, { class: "btn btn-primary btn-lg", style: "width: 100%;" } %>
mirap
  • 1,216
  • 12
  • 22
0

If you want to pass params too then do

<%= link_to student.name,  controller: "users", action: "show", id: student.id, partial: "profile"  %> 
gsumk
  • 749
  • 10
  • 15