繁体   English   中英

无论如何,要使由Best_In_place管理的对象也成为链接?

[英]Is there anyway to make an object managed by Best_In_place also be a link?

我正在使用Best In Place宝石

这是我的对象的一个​​示例:

<h5><%= best_in_place node, :name, as: :input, activator: "#edit-node-title-#{node.id}" %> <%= link_to "<i class='fa fa-pencil'></i>".html_safe, "#", id: "edit-node-title-#{node.id}" %></h5> 

但是我要做的是将node.name属性显示为常规链接。

所以只是link_to node.name, node

我如何结合两者?

您可以将“ Best in Place标签包装Best in Place link_to标签内:

<h5>
  <%= link_to node_path(node) do %><!-- Or whatever path you want to link_to --> 
    <%= best_in_place node, :name, as: :input, activator: "#edit-node-title-#{node.id}" %>
  <% end %>
  <%= link_to "#", id: "edit-node-title-#{node.id}" do %>
    <i class='fa fa-pencil'></i>
  <% end %>
</h5>

我还编辑了您的激活器链接,所以它也是一个块。 这未经测试,但应该可以。

使用display_with选项? 它需要一个助手或过程。 我希望有一个帮助器,但是为了简洁起见,我将其与proc一起显示:

<%= best_in_place node, :name, as: :input, 
                               activator: "#edit-node-title-#{node.id}" 
                               display_with: proc{|node| link_to node.name, node_path(node) }
%> 
<%= link_to "<i class='fa fa-pencil'></i>".html_safe, "#", id: "edit-node-title-#{node.id}" %>

暂无
暂无

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

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