elias_t
elias_t

Reputation: 83

create a rails dropdown search by category

I have a auction model and a category model. Auction belongs_to category and category has_many auctions How can i build a dropdown search by category in first page for auctions?

Upvotes: 2

Views: 3592

Answers (1)

Amar
Amar

Reputation: 6942

In your views

<%= select_tag "category_id", options_from_collection_for_select(Category.all, "id", "name") %>

By default you can display all the auction no matter with category On change of category form will submit based on category_id you can fetch the auctions

For Basic search you can refer railscasts

Upvotes: 2

Related Questions