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

Shouldn't the bip_value contain the value of display_value, and not value? #415

Open cipacda opened 10 years ago

cipacda commented 10 years ago

This would help in cases where I have a select for another type, which is a child of the current object.

stereodenis commented 10 years ago

@cipacda could you provide code, that not working?

cipacda commented 10 years ago

best_in_place_if editable, payment, :payment_method, :as => :select, :collection => PaymentMethod.all. each_with_object({}){|o, h| h[o.id.to_s] = o.name }

:payment_method is an object which has an id and a name. I would like to be able to display the name of the current payment_method selected.

cipacda commented 10 years ago

Currently I added the following hack: best_in_place_if editable, payment, :payment_method_id, :as => :select, :collection => PaymentMethod.all. each_with_object({}){|o, h| h[o.id.to_s] = o.name }

and updated the controller's update action to deal with :payment_method_id, which is not ideal.

stereodenis commented 10 years ago

@cipacda what about :display_as option?

seuros commented 10 years ago

display_as/with is bad, don't use it.

stereodenis commented 10 years ago

@cipacda @seuros :value?

seuros commented 10 years ago

:value, is what he needs i think. for info display_as/with is not thread-safe and won't work in a multiserver setup. We probably need to remove it and use a frontend script to format the reply.

cipacda commented 10 years ago

:value only updates the 'bip-content-original' and not the 'bip-value', the one that looks to be the one used to display the value.

See https://github.com/bernat/best_in_place/blob/master/lib/best_in_place/helper.rb lines 54 and 59.

cipacda commented 9 years ago

Is anyone still looking at this? Or can anyone give me a reason for why this cannot be done?

stereodenis commented 9 years ago

@cipacda maybe @seuros

stereodenis commented 9 years ago

@cipacda is it actual for latest master? I made some improvements for collection parameter

cipacda commented 9 years ago

@stereodenis On the latest master, the issue I am having is that when using best_in_place_if, if the value should not be editable, I get the id displayed, and not the name. This is what I am passing to the collection parameter:

:collection => entries.each_with_object({}){|o, h| h[o.id.to_s] = o.name }

stereodenis commented 9 years ago

@cipacda could you show me the output of this entries.each_with_object({}){|o, h| h[o.id.to_s] = o.name } and the data-bip-collection output or make a test app for this issue