Search code examples
ruby-on-railsbest-in-place

Rails best_in_place gem while clicking on the label name


I am using the best in place gem - which is great. Only thing is that I want the user to be able to click not just the best in place element in order to edit it, but also the label. Lets say I have this best in place element:

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

I want to be able to click the Open Hours in order to open the edit element. Is it possible?

Thanks


Solution

  • For 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 view you will need to make each id-identifier 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 %>