[英]how to put controller/action in link_to rails 4.1
I have: 我有:
<%= button_to '+',{:controller=>"line_items",:action=>'create',:menu_id=> line_item.menu_item,:remote=>true}%>
I have put same code for link: 我为链接放置了相同的代码:
<%= link_to '+',{:controller=>"line_items",:action=>'create',:menu_id=> line_item.menu_item,:remote=>true}%>
But link_to
is redirect me to the line_item_index page.I want that link_to will work like this button.please help me i am new in rails. 但是
link_to
将我重定向到line_item_index页面。我希望link_to可以像此按钮一样工作。请帮助我,我是新手。
link_to uses http GET for the resource you're linking while button_to uses http POST to your controller action. link_to对要链接的资源使用http GET,而button_to对控制器操作使用http POST。 adding
:method => :post
explicitly to your link_to tag makes it behave as http POST event 将
:method => :post
显式添加到您的link_to标记中使其表现为http POST事件
method link_to
creates link and method button_to
creates form. 方法
link_to
创建链接,方法button_to
创建表单。 They are not the same. 她们不一样。 From
button_to
you are using the form with method POST and it works ok, but with link_to
you are using method GET, and this is a problem. 在
button_to
您正在将表单与POST方法一起使用,并且可以正常工作,但是在link_to
您正在使用GET方法,这是一个问题。
To solve the problem, try this: 要解决此问题,请尝试以下操作:
link_to '+',{:controller=>"line_items",:action=>'create', :menu_id=> line_item.menu_item, :remote=>true, method: :post}
more explanation at: 更多说明,请访问:
http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.