我有一种方法可以进行分页查找调用,例如..
1
coll = paginate(:all, lambda {{:conditions => ['status = ? AND expires < ?', 'a', DateTime.now]}}, :select => Constants::POST_FIELDS,
:order => 'posts.ratings DESC', :include => [{:poster => :poster_friends}, :category], :per_page => Constants::LISTINGS_PER_PAGE,
:page => page)
当此调用运行时,它只是忽略生成的查询中的条件。
2
如果我在 named_scope 中尝试它,我会收到类似的错误。
named_scope :featured_all, lambda {{:conditions => ['status = ? AND expires < ?', 'a', DateTime.now], order => 'posts.ratings DESC', :include => [{:poster => :poster_friends}, :category],
:select => Constants::POST_FIELDS}}
命名范围错误:
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/keys.rb:47:in `assert_valid_keys'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2101:in `with_scope'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:113:in `__send__'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:113:in `with_scope'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:174:in `method_missing'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:188:in `load_found'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:166:in `proxy_found'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:109:in `is_a?'
/usr/lib/ruby/gems/1.8/gems/hirb-0.3.1/lib/hirb/formatter.rb:78:in `determine_output_class'
/usr/lib/ruby/gems/1.8/gems/hirb-0.3.1/lib/hirb/formatter.rb:48:in `format_output'
/usr/lib/ruby/gems/1.8/gems/hirb-0.3.1/lib/hirb/view.rb:213:in `render_output'
/usr/lib/ruby/gems/1.8/gems/hirb-0.3.1/lib/hirb/view.rb:126:in `view_output'
对于#1。我做错了什么,为什么忽略条件?
对于 #2 为什么会出现这个错误?而且,我如何通过 :page 和 per_page 参数来限制 named_scope 中的查询。
谢谢