Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrate Mongoid and CanCan

Have somebody tried to rewrite CanCan ActiverRecordAddtions for Mongoid http://github.com/ryanb/cancan/blob/master/lib/cancan/active_record_additions.rb

Regards, Alexey Zakharov

like image 421
Alexey Zakharov Avatar asked Sep 23 '10 08:09

Alexey Zakharov


People also ask

Can you use Prisma with MongoDB?

Data modeling To do that in MongoDB, you can include one document's _id field in another document. In this instance, Prisma can assist you in organizing this related data and maintaining referential integrity of the data.

Can you use MongoDB with Nextjs?

Developer productivity is another factor to consider when choosing a development stack for application development. Next. JS and MongoDB are an excellent combination to help you get your next application up and running.

How does MongoDB connect to remote host?

Short answer. Login to your machine, open mongodb configuration file located at /etc/mongod. conf and change the bindIp field to your machine ip address (it is the same ip address which you are using to ssh to your machine), after that restart mongodb server.

Can I use MongoDB with Netlify?

You can use the free forever tier of MongoDB Atlas, which is an M0 sized cluster. You can also use the free plan that Netlify offers.


1 Answers

I've managed to get CanCan and Mongoid (version 2) to work together pretty well on a rails 3 app. Still get some errors here and there related to conditions in the permission definition (the Ability model).

I just put the contents of this gist into a file in config/initializers:

  • http://gist.github.com/561639

The condition hashes are almost the same as with ActiveRecord:

# can only manage own account
can :manage, User, :_id => current_user.id

I'm still working on how to use more advanced Mongoid::Criteria conditions, but you can always use a block to do more complex conditions:

# can only manage own account
can :eat, Cake do
  current_user.jobs.any?{ |job| job.title == 'Peasant'}
end
like image 109
bowsersenior Avatar answered Oct 18 '22 09:10

bowsersenior