Rails best_in_place gem when clicking on a tag name

I use the best of its kind gem - it's great. The only thing I want so that the user can click not only the best element in place to edit it, but also a shortcut. Let's say I have a better element:

<b>Open Hours</b> <%= best_in_place @provider, :open_hours, :type => :select, :collection => Provider::PROVIDERS_HOURS %> 

I want to be able to click Open Hours to open an edit item. Is it possible?

thanks

+4
source share
2 answers

For a single instance of a class, you can simply

 <b id='edit-open-hours'>Open Hours</b> <%= best_in_place @provider, :open_hours, type: :select, collection: Provider::PROVIDERS_HOURS, activator: '#edit-open-hours' %> 

If you want to do this with a list, you will need to make each id unique with an id

 <b id='edit-<%= @provider.id %>'>Open Hours</b> <%= best_in_place @provider, :open_hours, type: :select, collection: Provider::PROVIDERS_HOURS, activator: '#edit-' + @provider.id.to_s %> 
+5
source

This was very useful, but a small correction: you must prefix the activator DOM element with the corresponding symbol (# for id, for class).

So the second example would be

 <%= best_in_place @provider, :open_hours, type: :select, collection: Provider::PROVIDERS_HOURS, activator: '#edit-' + @provider.id.to_s %> 
+3
source

All Articles