Ruby on rails 3 link_to controller and action

别说谁变了你拦得住时间么 提交于 2019-12-30 02:33:06

问题


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?


回答1:


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

See url_for.




回答2:


Also with CSS:

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



回答3:


If you want to pass params too then do

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


来源:https://stackoverflow.com/questions/5607155/ruby-on-rails-3-link-to-controller-and-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!