Has anyone had success having Rails 3, Mongoid and Inherited Resources working? Any tips for making it happen? I would love to use both gems.
Currently I am running into:
undefined method `scoped'
On index actions.
Thanks!
BTW a workaround for the scoped issue is to override collection like so:
class CampaignsController < InheritedResources::Base
def collection
@campaigns ||= end_of_association_chain.paginate(:page => params[:page])
end
end
But I am looking for a more holistic approach
Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important. It makes your controllers more powerful and cleaner at the same time.
Mongoid supports inheritance in both top level and embedded documents.
If you are using only mongoid, what you should do is to overwrite the default collection behavior in Inherited Resources. The default behavior is this:
https://github.com/josevalim/inherited_resources/blob/master/lib/inherited_resources/base_helpers.rb#L22-24
That said, the following should do the trick:
module MongoidActions
def collection
get_collection_ivar || set_collection_ivar(end_of_association_chain.all)
end
end
InheritedResources::Base.send :include, MongoidActions
You can even default the collection to paginate and have pagination for free in all pages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With