Skip to content

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

@sscirrus

Description

@sscirrus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions