I have a navbar
button:
<%= link_to new_post_path do %>
<a class="btn-navbar"><i class="fa fa-plus" aria-hidden="true"></i></a>
<% end %>
It does not allow me to click it and navigate to the correct page.
If I remove the <a>
tags, it works but I need the <a>
because its have the correct class associated with it to style the button.
The above code is styled correctly but when trying to click it it does not link to the right page.
答案 0 :(得分:2)
将类添加到helper的链接,以将其应用于a标记。
<%= link_to new_post_path, class: 'btn-navbar' do %>
<i class="fa fa-plus" aria-hidden="true"></i>
<% end %>
如果您正在使用官方字体 - 真棒rails:
https://github.com/FortAwesome/font-awesome-sass
<%= link_to icon('plus'), new_post_path, class: 'btn-navbar' %>
答案 1 :(得分:0)
将a标签替换为span,然后将span赋予与a标签相同的类,这应该会给你相同的结果
<span class="btn-navbar">your code goes here</span>