Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Why am I not getting any data inside the dropdown in browser?

Rails • Asked by Rajnish Singh

My Controller has following code
@select = Store.find(current_user.store_id)
My View has:

<%= form_with(model:@store, local: true) do |f| %>
<%= :id, options_for_select(, :id), {:include_blank => '--Select Item--'}, { :class => 'form-control' } %>
<%= f.submit 'Submit', :class => 'btn btn-sm btn-primary m-t-n-xs' %>
<% end %>

<%= debug( %> This gives me the store name

Why am I not getting any data inside the Dropdown in browser?

Your syntax seems to be off. Try something like this: :id, options_from_collection_for_select(@select, :id, :name)

Getting error

undefined method `map' for #Store:0x00007fd290f55ba8
Did you mean? tap

Hi Rajnish,

options_for_select expects an array or hash of options, see

Your query - @select = Store.find(current_user.store_id) only returns a single object which won't work to populate a select field like you're wanting.

So just to clarify what you're after, can a User have multiple stores or only one? Your query suggests only one, but your desired result suggests multiple so I'm a little confused.

Jacks answer is spot on if a user can have multiple stores. If so, you should adjust your query to something like @select = current_user.stores if you have your associations setup correct.

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 29,763+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.