1

A noob here. I've only just started to learn ROR, and I'm having a problem with a drop down menu, that allows the user to select a project from a database. I have the drop down menu working, however instead of the project names, it shows something like Project:0xb61fbdbc.

    <%= f.label :project_name %><br />
    <%= f.select(:project_name, Project.all, :prompt => "Select a Project") %>

I have searched,and searched and had no luck. Hopefully someone can help.

Thanks in advance.

1 Answer 1

6

This should help, provided that you have a name attribute in your Project model:

<%= f.select(:project_name, Project.all.map {|p| [p.name,p.id]}, :prompt => "Select a Project") %>
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you very much. I knew it would be something simple :)
You can find more on select boxes in form builders here guides.rubyonrails.org/…. Can you accept the answer if it solved your problem?
I noticed that it would now show the name of the project, but when I submitted, it displayed as the id of that project name. I changed the code you suggested to <%= f.select(:project_name, Project.all.map {|p| [p.project_name]}, :prompt => "Select a Project") %> Which now works perfectly, Thank you.
This really depends on what exactly you want to be submitted from the select box. Submitting names from a single selection box is OK when the names are unique, but generally you'd want to use unique attributes such as IDs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.