Search code examples
ruby-on-railsruby-on-rails-4best-in-place

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


I am using the Best In Place gem.

This is an example of my object:

<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> 

But what I want to do is have the node.name attribute be shown as a regular link.

So just link_to node.name, node.

How do I combine the two?


Solution

  • Use the display_with option? It takes a helper or proc. I would prefer a helper, but for brevity I show it with a 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}" %>