将类添加到 link_to 块 [英] Adding a class to link_to block

查看:43
本文介绍了将类添加到 link_to 块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码显示删除"链接:

I have a following code which displays a 'delete' link:

<%= link_to :class => 'some_class', :method => :delete, :data => { :confirm => 'Are you sure?' }  do
  <span>Delete</span>
<% end %>

但由于某种原因,ROR 没有将 some_class 添加到 a 标签.你知道我能做些什么来解决它吗?提前致谢.

But for some reason ROR is not adding some_class to a tag. Have you any idea what can i do to fix it ? Thanks in advance.

推荐答案

您需要添加 URL 作为第一个参数,然后添加 html 选项,例如:

You need to add the URL as the first parameter, then the html options, e.g.:

<%= link_to resource_path(@resource), :class => 'some_class', :method => :delete, :data => { :confirm => 'Are you sure?' }  do
  <span>Delete</span>
<% end %>

这篇关于将类添加到 link_to 块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆