开发者

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 ?


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")


I guess that you are looking for something like:

@events = Event.where(:trainer => "0")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜