Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 711
Jason Yost Avatar asked Apr 09 '11 19:04

Jason Yost


People also ask

What is action controller rails?

Action Controller is the C in MVC. After the router has determined which controller to use for a request, the controller is responsible for making sense of the request and producing the appropriate output.

What are actions in Ruby on Rails?

Action View templates are written using embedded Ruby in tags mingled with HTML. To avoid cluttering the templates with boilerplate code, several helper classes provide common behavior for forms, dates, and strings. It's also easy to add new helpers to your application as it evolves.

What decides which controller receives Ruby?

Routing decides which controller receives which requests. Often, there is more than one route to each controller, and different routes can be served by different actions. Each action's purpose is to collect information to provide it to a view.


2 Answers

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

See url_for.

like image 117
Jakub Hampl Avatar answered Oct 06 '22 00:10

Jakub Hampl


Also with CSS:

<%= link_to "Purchase", { :controller => :transactions, :action => :purchase }, { class: "btn btn-primary btn-lg", style: "width: 100%;" } %> 
like image 36
mirap Avatar answered Oct 06 '22 00:10

mirap