Ruby on Rails: How to change the Foriegn Key values on a collection_select drop down? -
I have drop down on my form which is a foreign key for any other table:
& lt; Div class = "field" & gt; & Lt; Td> & Lt;% = f.label "# {column_name}"% & gt; & Lt; / Td> & Lt; Td> & Lt;% = f.collection_select "# {column_name}", table. All ,: id :: message_id% & gt; & Lt; / Td> & Lt; / Div & gt; In the "table" there is a column "message_id" which is a foreign_ for a separate table "message".
The "Message" table contains all the text / string in my application.
When I load this code on my page it will give me a drop list of all records but it will only show the foreign key ID number, pointing to the "message" table.
How do I change the foreign key ID number in the drop-down to switch to the message content in my message table?
Try this: f.input "# {column_name}" ,: archive = & gt; ; Table. All Select {| T | [Messages.find (t.message_id) .message_content, t.id]} It is not very efficient, but I think it will work.
Comments
Post a Comment