继承资源和Mongoid

Jon*_*han 5 ruby-on-rails mongodb mongoid inherited-resources ruby-on-rails-3

有没有人成功使用Rails 3,MongoidInherited Resources?有任何提示可以实现吗?我很乐意使用这两种宝石.

目前我遇到:

undefined method `scoped'
Run Code Online (Sandbox Code Playgroud)

关于索引操作.

谢谢!


BTW范围问题的解决方法是覆盖集合,如下所示:

class CampaignsController < InheritedResources::Base

  def collection
    @campaigns ||= end_of_association_chain.paginate(:page => params[:page])
  end

end
Run Code Online (Sandbox Code Playgroud)

但我正在寻找一种更全面的方法

Jos*_*lim 10

如果您只使用mongoid,那么您应该做的是覆盖Inherited Resources中的默认集合行为.默认行为是这样的:

https://github.com/josevalim/inherited_resources/blob/master/lib/inherited_resources/base_helpers.rb#L22-24

那说,以下应该做的伎俩:

module MongoidActions
  def collection
    get_collection_ivar || set_collection_ivar(end_of_association_chain.all)
  end
end

InheritedResources::Base.send :include, MongoidActions
Run Code Online (Sandbox Code Playgroud)

您甚至可以将集合默认为分页,并在所有页面中免费分页.