Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to add condition to rails find

I have Event model which contains following fields

    string   "name"
    date     "start_at"
    date     "end_at"
    datetime "created_at"
    datetime "updated_at"
    string   "trainer"
    string   "venue"
    string   "description"
    boolean  "holy"
    integer  "nxt"

And I have also save holidays in the event that contains trainer as '0' so I need to find all the holidays on event table. Can expert give me some idea to implement this ?

like image 836
Coder Avatar asked Nov 23 '25 13:11

Coder


2 Answers

Rails has dynamic finders. I'm not sure if I understand your question correctly, but this code should find all Events that have trainer = 0. To find one holiday use:

Event.find_by_trainer("0")

To find all, use:

Event.find_all_by_trainer("0")
like image 181
Max Avatar answered Nov 25 '25 04:11

Max


I guess that you are looking for something like:

@events = Event.where(:trainer => "0")
like image 24
DanneManne Avatar answered Nov 25 '25 02:11

DanneManne