edrich rocha edrich rocha - 1 month ago 7
Ruby Question

select_fields in rails how to store value instead of name

how do i display the name of the room category and then store the id of it instead of the name
i have tried using the below statement

= f.select :room_category_id, RoomCategory.all.pluck('name'), {}, class: "form-control"


then i replaced it too the below statement , names get displayed but i cant stroe the value

= f.select :room_category_id, RoomCategory.all.pluck('name'), {}, class: "form-control"

Answer

Try this

= f.select :room_category_id, RoomCategory.collect{|p| [p.name, p.id]}, {},class: "form-control"

Hope, this will help you.

Comments