简体   繁体   中英

How to pass a select menu in ransack gem

I am trying to implement a search field with a dropdown select menu with options for category field using ransack gem. this is what I am trying to acheive

<%= f.select :category, ["",  "Art", "Books and Movies", "Clothing","Collectibles", "Computers & Related", "Construction Materials", "Crafts & Hobbies", "Entertainment" %>

but I don't know how to do it using ransack

It looks like you're missing a closing bracket:

<%= f.select :category, ["",  "Art", "Books and Movies", "Clothing","Collectibles", "Computers & Related", "Construction Materials", "Crafts & Hobbies", "Entertainment"] %>

That should work, I just tested something similar.

You could also do something like:

<%= f.select :category, Category.all.collect{|c| [u.name, u.name]} %>

Assuming you have a category model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM