简体   繁体   English

如何使用link_to在rails 3上创建没有href属性的链接?

[英]How to create a link without href attribute on rails 3 with link_to?

i'm not able to create a link without the href attribute with link_to 如果没有带有link_to的href属性,我将无法创建链接

<a class="some-class" title="some-title"></a>

i was searching in some documentation but i haven't seen anything related to this problem. 我在搜索某些文档,但没有看到与此问题有关的任何内容。

FYI this type of link is provided to have a clickable item with the title attribute and without the classic '#' in the url. 仅供参考,提供这种类型的链接的目的是提供一个带有标题属性且网址中没有经典“#”的可点击项。 i'm open to other solutions to the problem. 我愿意接受其他解决方案。

Any suggestion? 有什么建议吗?

You should check out the Tag Helper . 您应该签出Tag Helper

This should do the trick: 这应该可以解决问题:

<%= tag "a", :class => "some_class", :title => "some_title"%>

you can just type it directly in the view 您可以直接在视图中输入

<a class="some-class" title="some-title"></a>

the link_to helper is used to get the baseurl link_to帮助程序用于获取基本URL

Each link should have href attribute. 每个链接应具有href属性。 You could set href to # like this: 您可以像这样将href设置为#

<%= link_to "#", class: "some-class", title: "some-title" do %>
  Whatever
<% end %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM