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

How to select foreign_key using friendly_id's hash_id? #617

Open sscirrus opened 5 years ago

sscirrus commented 5 years ago

My project has a select box where one can choose each user's project, but user.project_id is set according to be project's hash_id, not its actual id. So, the browser only knows the user and the project's hash_id.

Here's the code I'm using (project is already defined):

<%= best_in_place user, :project_id, as: :select, collection: @projects.collect{|d| [d.id, d.name]}, value: project.hash_id %>

The above code doesn't work - it ignores the value and sets everything to the first option, regardless of what the DB value is. I'd like it so it shows the correct value.