link_to_除非这样做
这是一个典型的 link_to_unless
:
<%= link_to_unless(@current_user.nil?, "Reply", { :action => "reply" }) %>
我怎样才能用块做同样的事情?
# non-functional
<%= link_to_unless(@current_user.nil?, ..., { :action => "reply" }) do %>
...
<% end %>
Here's a typical link_to_unless
:
<%= link_to_unless(@current_user.nil?, "Reply", { :action => "reply" }) %>
How can I do the same thing with a block?
# non-functional
<%= link_to_unless(@current_user.nil?, ..., { :action => "reply" }) do %>
...
<% end %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
link_to_unless
已接受一个块。不过,您需要传递一个块参数来访问链接标题参数。此时,您必须问自己是否更容易执行 if/else 语句。
link_to_unless
already accepts a block. You need to pass a block argument for to access the link title parameter, though.At this point though you have to ask yourself if it's just easier to do and if/else statement.
把它放在助手中
应该可以工作..虽然没有经过测试
put this in a helper
should work.. though not tested