bernat / best_in_place

A RESTful unobtrusive jQuery Inplace-Editor and a helper as a Rails Gem
http://blog.bernatfarrero.com/in-place-editing-with-javascript-jquery-and-rails-3/
1.2k stars 571 forks source link

Added an option for an "id_appendix" #468

Open swunderlich opened 9 years ago

swunderlich commented 9 years ago

I was (successfully) updating localized fields in a mongodb using mongoid. But my test failed due to ambiguous ids. The actual functionality uses a custom url. As I absolutely wanted to pass the test I added this little feature.

To get an idea of the actual code:

<% @product.descriptions.each do |desc| %>
    <div class="form-group">
      <% I18n.available_locales.each do |locale| %>
          <% I18n.locale = locale %>
          <div class="input-group">
            <span class="input-group-addon"><%= locale.to_s.upcase %></span>
            <%= best_in_place desc, :name,  class: "form-control", url: "/set_desc/#{desc.id}/#{locale.to_s}", :id_appendix => locale %>
          </div>
      <% end %>
    </div>
<% end %>