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 574 forks source link

Problem with select #556

Open ethereumdegen opened 8 years ago

ethereumdegen commented 8 years ago

So i have this code in my view:

<% my_coll = RentableCategory.all.map{ |cat| [cat.id.to_s, cat.name] }.to_h %> <%= best_in_place @rentable, :rentable_category, :as => :select, :collection => my_coll, :value => @rentable.rentable_category.id %>

The variable my_coll has this hash: {"29"=>"Parties", "30"=>"Media", "27"=>"Camping Gear", "26"=>"Home Improvement"}

The problem is, this outputs the following HTML:

<span data-bip-type="select" data-bip-attribute="rentable_category" data-bip-collection="[[&quot;29&quot;,&quot;Parties&quot;],[&quot;30&quot;,&quot;Media&quot;],[&quot;27&quot;,&quot;Camping Gear&quot;],[&quot;26&quot;,&quot;Home Improvement&quot;]]" data-bip-object="rentable" data-bip-original-content="26" data-bip-skip-blur="false" data-bip-url="/rentable/242" data-bip-value="#<RentableCategory:0x0000000a059330>" class="best_in_place bip-placeholder" id="best_in_place_rentable_242_rentable_category">-</span>

This makes the select element be invisible with no value (see the data-bip-value attribute all messed up) and then when I click on it, the data-bip-value attribute becomes '26' (which is is supposed to be) and then the dropdown is visible. How do i make it have the correct default value from the get-go?