Checking if ActiveRecord find returns a result

后端 未结 7 1499
孤独总比滥情好
孤独总比滥情好 2021-02-07 08:03

I\'m trying to check if a find method returns a result. My find method is the following:

post = Post.find(:all, :conditions => { :url => params[\'url\'] },         


        
7条回答
  •  迷失自我
    2021-02-07 08:22

    if post doesn't contain any result it will be an empty list and then:

    post.empty?
    

    will return true.

提交回复
热议问题