Checking if ActiveRecord find returns a result

后端 未结 7 1507
孤独总比滥情好
孤独总比滥情好 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:29

    You can try ActiveRecord::Base.exists? before

    Post.exists?(:conditions => { :url => params['url'] })
    

提交回复
热议问题