Just started coding in Ruby on Rails and have managed to create the basic CRUD functionality for my app.
I can also list them all. Now I would like to create a filter for the user to interact with.
Database Schema
create_table "nades", force: :cascade do |t|
t.string "title"
t.integer "grenade"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "map_id"
end
The "grenade" can have a value from 1-4, corresponding to a specific grenade:
[[1,"smoke"], [2,"flash"], [3,"molotov"], [4,"he-grande"]
Now I'm trying to create a filter with 4 buttons in the view. Where you can toggle each nade on/off to show or hide them in the results.
[x]Smoke [ ]Flash [ ]Moltov [x]HE
This should only return the nades where grenade = [1,4]
After some reading it looks like scoped would be nice to use to manage this. However I'm not sure how to make it work as I want.
Was thinking of doing something like:
scope :by_nade, -> grenade { where(grenade: grenade) if status.grenade? }
However this only allows me to get 1 specific nade type from the database. Is it posible to send multiple parameters like:
http://localhost:3000/nades/?by_nade=1,2 ??
Or is it a better solution to my problem?