Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Simple Ruby on Rails Application Customizing Forms Adding a Dropdown

Dropdown not working for new users

When I add new users like in the video, no matter which user I choose from the dropdown menu, it always saves it in the database as the first user that I created. Any ideas why that's the case? Also, I don't know if this matters but I am using Rails 4.

This is the code for my form, which simply gets rendered on my view:

    <%= simple_form_for @status, defaults: { input_html: { class: 'form-horizontal' } } do |f| %>
        <%= f.input :user_id, collection: User.all, label_method: :full_name %>
        <%= f.input :content %>
        <%= f.button :submit %>
    <% end %>

EDIT: I just fixed the problem. There was an issue with the way I was displaying the user's name in the show and index views but I just fixed it. Thanks anyway!

Just added the code for my form.

Charles Smith
Charles Smith
7,575 Points

If you remove the collections features and try it, do you still get the same user? EG: does the dropdown show different user ids? how about if you save it? do you still get the same ids?

The dropdown shows different ids, so that's correct. But what do you mean about saving?

1 Answer

Hello,

I haven't used the simple_form gem myself(I find forms to be easy enough without it). But looking at their documentation, you might want to use

<%= f.association :user %>

instead of your

<%= f.input :user_id, collection: User.all, label_method: :full_name %>

line. Please let us know if that helps or not.

Still not working. Also, I don't know if this helps identify the problem or now, but I took off the full name thing so that I could see the ids for each user and they change every time I reload the page. Is that supposed to be happening?