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

display_with and as: :select don't work together? #448

Closed shyrahnama closed 9 years ago

shyrahnama commented 9 years ago

Hi there,

I'm trying to use display_with to show a default value if a field isn't set and it's not working at all

The model is a user model and we allow users to not have a timezone, in which case I want to show the default configured timezone.

best_in_place u, :time_zone, as: :select, url: admin_user_path(u), collection: ActiveSupport::TimeZone.zones_map.keys.select{|tz| tz.include?("US")}.map{|tz| [tz,tz]}, display_with: lambda{ |v| v ? v : "#{Rails.application.config.time_zone} (default)" }

Am I missing something obvious?

Thxs.

seuros commented 9 years ago

display_with is not thread safe. It better to add this check in your model if possible.

shyrahnama commented 9 years ago

Perfect. Thanks for the quick reply!

On Thu Feb 12 2015 at 7:43:21 AM Abdelkader Boudih notifications@github.com wrote:

display_with is not thread safe. It better to add this check in your model if possible.

— Reply to this email directly or view it on GitHub https://github.com/bernat/best_in_place/issues/448#issuecomment-74081323 .

soberstadt commented 9 years ago

Should this be closed then?

shyrahnama commented 9 years ago

Yep, it can be closed. Added an instance method to my model to return the default value and it works fine.

codemilan commented 9 years ago

@shyrahnama Can you show how you did that ? I'm too facing the same problem but unable to solve that. Hoping you will help.