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

collection select, names don't display if condition not met #445

Open OShalaby-zz opened 9 years ago

OShalaby-zz commented 9 years ago

Hi, thanks alot for the great gem!

I have profile, area and city models in my rails app:

<%= best_in_place_if current_user.profile == @profile, @profile, :area_id, as: :select, collection: Area.all.map { |i| [i.id, i.name]}, place_holder: "Area (Click Me!)" %>

<%= best_in_place_if current_user.profile == @profile, @profile, :city_id, as: :select, collection: City.all.map { |i| [i.id, i.name]}, place_holder: "City (Click Me!)" %>

The problem here is I have a condition so that the current user can edit his profile only (obviously). and it shows the names of the areas and cities no problems, but when I visit another profile I don't see the names anymore, just the ids...If I remove the condition I see names of area and city fine on other profiles but that means any user can edit any profile...anyway of making the names showing not a part of the condition?

Also how can I go on about dynamic selection? (optgroup) i.e.

  <%= f.grouped_collection_select :area_id, City.all, :areas, :name, :id, :name, include_blank: true %>

Thanks

stereodenis commented 9 years ago

@OShalaby are you using the latest version of gem from master? Could you show the html output of you code above?

OShalaby-zz commented 9 years ago

@stereodenis hi!, thanks for your reply. I have not specified a version in the Gemfile, but bundle show says version 3.0.3.

from the logged in profile the areas' html output is:

<span class="best_in_place" data-bip-attribute="area_id" data-bip-collection="[[1,&quot;10th of Ramadan&quot;],[2,&quot;6th of October&quot;],[3,&quot;Abbasyia&quot;],[4,&quot;Abou Rawash&quot;],[5,&quot;Agouza&quot;],[6,&quot;Ain Shams&quot;],[7,&quot;Ard El Golf&quot;],[8,&quot;Dokki&quot;],[9,&quot;Downtown&quot;],[10,&quot;El Katameya&quot;],[11,&quot;El Manial&quot;],[12,&quot;El Rehab&quot;],[13,&quot;El Sheikh Zayed&quot;],[14,&quot;El Shorouk&quot;],[15,&quot;El Zeitoun&quot;],[16,&quot;Faisal&quot;],[17,&quot;Garden City&quot;],[18,&quot;Ghamra&quot;],[19,&quot;Giza Square&quot;],[20,&quot;Hadayek El Ahram&quot;],[21,&quot;Haram&quot;],[22,&quot;Heliopolis&quot;],[23,&quot;Helwan&quot;],[24,&quot;Maadi&quot;],[25,&quot;Madinaty&quot;],[26,&quot;Masaken Sheraton&quot;],[27,&quot;Misr El KAdema&quot;],[28,&quot;Mohandessine&quot;],[29,&quot;Mokattam&quot;],[30,&quot;Nasr City&quot;],[31,&quot;New Cairo&quot;],[32,&quot;New Nozha&quot;],[33,&quot;Obour City&quot;],[34,&quot;Shobra&quot;],[35,&quot;Shobra El Kheima&quot;],[36,&quot;Zamalek&quot;],[37,&quot;Agamy&quot;],[38,&quot;Asafra&quot;],[39,&quot;Azarita&quot;],[40,&quot;Bab Sharq&quot;],[41,&quot;Bakos&quot;],[42,&quot;Bolkly&quot;],[43,&quot;Camp Cheaser&quot;],[44,&quot;Carrefour&quot;],[45,&quot;Cleopatra&quot;],[46,&quot;Glim&quot;],[47,&quot;Ibrahimia&quot;],[48,&quot;Kafr Abdo&quot;],[49,&quot;Lauran&quot;],[50,&quot;Maamoura&quot;],[51,&quot;Mandara&quot;],[52,&quot;Manshia&quot;],[53,&quot;Miami&quot;],[54,&quot;Moharam Bek&quot;],[55,&quot;Montazah&quot;],[56,&quot;Mostafa Kamel&quot;],[57,&quot;Raml Station&quot;],[58,&quot;Roushdy&quot;],[59,&quot;San Stefano&quot;],[60,&quot;Semouha&quot;],[61,&quot;Shatby&quot;],[62,&quot;Sidi Bishr&quot;],[63,&quot;Sidi Gaber&quot;],[64,&quot;Stanly&quot;]]" data-bip-object="profile" data-bip-placeholder="Area (Click Me!)" data-bip-type="select" data-bip-url="/profiles/4" id="best_in_place_profile_4_area_id">Agouza</span>

and for the city also from current profile:

<span class="best_in_place" data-bip-attribute="city_id" data-bip-collection="[[1,&quot;Cairo&quot;],[2,&quot;Alexandria&quot;]]" data-bip-object="profile" data-bip-original-content="1" data-bip-placeholder="City (Click Me!)" data-bip-type="select" data-bip-url="/profiles/4" data-bip-value="1" id="best_in_place_profile_4_city_id">Cairo</span>

However from other profiles I see:

<b>4, 1, Egypt ·</b>

Thanks

neonix20b commented 9 years ago

I have this issue too in latest version of gem from master. @OShalaby, how did you resolve it?

OShalaby-zz commented 9 years ago

hey @neonix20b I removed the condition from the best_in_place tag and placed it before it so it would be :

<% if current_user.profile == @profile %>
  <%= best_in_place @profile, :area_id, as: :select, collection: Area.all.map { |i| [i.id, i.name]}, place_holder: "Area (Click Me!)" %>
<% else %>
  <%= @profile.area.name %>
<% end %>
stereodenis commented 9 years ago

@neonix20b @OShalaby I could help you if you provide a sample app with this bug