简体   繁体   English

Rails 4 link_to选项包含数据

[英]Rails 4 link_to option to include data

i have a link as follows 我有如下链接

<a title="" class="btn btn-default btn-icon btn-xs tip" href="#" data-original-title="Edit"><i class="fa fa-pencil"></i></a>

what i have tried? 我尝试了什么?

<%= link_to "<i class="fa fa-pencil"></i>".html_safe, edit_admin_category_path(category), :class => 'btn btn-default btn-icon btn-xs tip', :data => {:original-title=>"Edit"} %>

Error: 错误:

/Users/harshamv/Sites/nomad/app/views/admin/categories/index.html.erb:28: syntax error, unexpected tIDENTIFIER, expecting ')'

Is there a way to use link_to without have to use the following format 有没有一种方法可以使用link_to而不必使用以下格式

<%= link_to(@profile) do %>
  <strong><%= @profile.name %></strong> -- <span>Check it out!</span>
<% end %>

Your approach will work, it's just a syntax error where you need to fix the double quotes. 您的方法将起作用,这只是语法错误,您需要在其中修复双引号。

<%= link_to "<i class='fa fa-pencil'></i>".html_safe, edit_admin_category_path(category), :class => 'btn btn-default btn-icon btn-xs tip', :data => {:original-title=>"Edit"} %>

You could also use content_tag which is a little cleaner 您也可以使用content_tag ,它更清洁

<%= link_to content_tag(:li, '', class: 'fa fa-pencil'), edit_admin_category_path(category), :class => 'btn btn-default btn-icon btn-xs tip', :data => {:original-title=>"Edit"} %>

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

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