ruby-on-rails-3 – find(:first)和find(:all)已弃用
发布时间:2020-12-16 20:50:01 所属栏目:百科 来源:网络整理
导读:我正在使用带有rails 3.2.12的RubyMine,我在IDE中得到了不推荐使用的警告.任何想法如何解决这个已弃用的警告? find(:first) and find(:all) are deprecated in favour of first and all methods. Support will be removed from rails 3.2. 解决方法 在@keit
我正在使用带有rails 3.2.12的RubyMine,我在IDE中得到了不推荐使用的警告.任何想法如何解决这个已弃用的警告?
find(:first) and find(:all) are deprecated in favour of first and all methods. Support will be removed from rails 3.2. 解决方法
在@keithepley评论后我改变了我的回答
#Post.find(:all,:conditions => { :approved => true }) Post.where(:approved => true).all #Post.find(:first,:conditions => { :approved => true }) Post.where(:approved => true).first or post = Post.first or post = Post.first! or post = Post.last or post = Post.last! 您可以从this locations阅读更多内容 弃用声明 Post.find(:all,:conditions => { :approved => true }) 更好的版本 Post.all(:conditions => { :approved => true }) 最佳版本(1) named_scope :approved,:conditions => { :approved => true } Post.approved.all 最佳版本(2) Post.scoped(:conditions => { :approved => true }).all (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |