Rails best_in_place gem while clicking on the label name

為{幸葍}努か 提交于 2019-12-06 04:38:56

问题


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


回答1:


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



回答2:


This was very helpful, but a small correction: you have to prefix the activator DOM element with the relevant 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 %>


来源:https://stackoverflow.com/questions/14113045/rails-best-in-place-gem-while-clicking-on-the-label-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!