Quantcast
Channel: Define the default value of a drop down menu from a class variable - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Define the default value of a drop down menu from a class variable

$
0
0

I have a list of books categories on my db. I can get the value of them inside my controller like this:

@categories = Book.uniq.pluck(:category) #programming, networking, infrastructure

And then, I can pass the value in the view to a drop down menu like this:

<%= s.select :category, options_for_select(@categories) %>

So, my question:

How I can define to be the selected default value of my drop down menu, the second value of the @categories?


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images