I have an object called "item" that has a "title" that can be linked to any URL. I have used the following code to allow the title to be edited in place using the Best in Place gem. The editing part works fine, but when the removes focus from the input box, the link is lost.
<%= best_in_place item, :title,
:display_with => :link_to,
:activator => "#edit-#{item.id}",
:helper_options => item.url %>
I have a feeling I am not setting the value for "helper_options" correctly.
How do I edit the code above so the link is restored with the updated text after the user changes the title? I can't find an example of this on the Best in Place github site, or anywhere else for that matter.
Late answer, but you never know who will was something similar? For your case, I think you want a block:
<%= link_to(item.url) do %>
<span><%= best_in_place item, :title,
:activator => "#edit-#{item.id}" %>
</span>
<% end %>
This assumes you want to edit the title, not the URL of the link.
For editing the link but using the title as the link body you would use lambda in display_with
= best_in_place item,
:url,
:display_with => lambda {
|url| link_to item.title, url
}
That's haml, I didn't test the exact snip but similar is working in an app I'm buidling
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With