Rails在ID上动态应用跳过导航

时间:2018-09-06 16:16:20

标签: ruby-on-rails

我正在通过跳过导航浏览和更新网站。我正在尝试使用具有动态但撞墙的id来创建动态锚标签。

<% Location.all.each do |location|%>
 <a href=<%="#{location.title}"%> class="skip">Skip to locations</a>
<% end %>

<%= content_tag :div, :class => "location", :data => {:id => location.id, :title => location.title, :latitude => location.latitude, :longitude => location.longitude} do %>
  <%= content_tag :div, location.title, :class => "location-title" , :id => "#{location.title}"%>

该ID在div上正确显示,但是没有将锚标记设置为ID。我尝试做:<%='#“#{location.title}”',但最终结果是:quote#{location.title} quote的链接

2 个答案:

答案 0 :(得分:0)

尝试使用<a href="#<%={location.title}%>" class="skip">Skip to locations</a>来避免ERB逃脱#符号

答案 1 :(得分:0)

您可以使用ActionView助手:

<%= link_to "Skip to locations", location.title, class: 'skip' %>