link_to的用法


<li>
<%= link_to 'Logout',:controller => :account,:action=>:logout,:method=>:post %>
</li>

提交logout的时候,总是卡着不动。
controller里去掉request.post之后,就可以。
但是request.post本身没有错。于是乎猜想是link_to的方法用错了,导致不是用post方法提交的。

进一步追查原因
状态栏显示:logout?method=post
html源码。

<a href="/account/logout?method=post">Logout</a>


看来应该是link_to用错了!

查了之前的用法,然后加了一个大括号!

<li>
<%= link_to 'Logout',{:controller => :account,:action=>:logout},:method=>:post %>
</li>

状态栏显示:logout
html源码

f.method = 'POST';


ok通过了。

查看api
link_to(*args, &block)

Creates a link tag of the given name using a URL created by the set of options. See the valid options in the documentation for url_for. It‘s also possible to pass a string instead of an options hash to get a link tag that uses the value of the string as the href for the link, or use :back to link to the referrer - a JavaScript back link will be used in place of a referrer if none exists. If nil is passed as a name, the link itself will become the name.
Signatures

link_to(name, options = {}, html_options = nil)
link_to(options = {}, html_options = nil) do
# name
end

关键点在这里,
link_to(name, options = {}, html_options = nil)
link_to的第只有三个参数,如果省略{}之后,最后的:method=>:post没有作为post方法提交到后台,而是直接作为参数传递到后台。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值