Ask A Question


You’re not receiving notifications from this thread.

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

Rajnish Singh asked in Rails

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.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,160+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.