Jason Yost
Jason Yost

Reputation: 4937

Ruby on rails 3 link_to controller and action

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?

Upvotes: 39

Views: 60700

Answers (4)

vidur punj
vidur punj

Reputation: 5861

For Rails 6:

 <%= button_to "SIGN IN", { controller: 'o_auth', action: :login }, { class: "btn btn-primary btn-lg", style: "width: 100%;", method: :get} %>

Upvotes: 0

gsumk
gsumk

Reputation: 891

If you want to pass params too then do

<%= link_to student.name,  controller: "users", action: "show", id: student.id, partial: "profile"  %> 

Upvotes: 0

mirap
mirap

Reputation: 1266

Also with CSS:

<%= link_to "Purchase", { :controller => :transactions, :action => :purchase }, { class: "btn btn-primary btn-lg", style: "width: 100%;" } %>

Upvotes: 11

Jakub Hampl
Jakub Hampl

Reputation: 40533

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

See url_for.

Upvotes: 58

Related Questions