Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Brandon Barrette
20,485 PointsUser Roles - any recommendations?
I want to add user roles to my site so that certain users can see certain pages, while others are prohibited because they don't have the right roles.
Anyone have recommendations on doing this? Should I create a roles model and go from there? Or is there a gem you would recommend for doing this effortlessly?
Thanks in advance for any help!
3 Answers
Richard Wigley
3,733 PointsCanCan is the most well known Gem. . It's pretty easy to work with, small and few dependencies. Though if feels a little 'magical' using the DSL - if you don't like magic he has a video where he builds up a similar authorization scheme from scratch. I've used both ways without a hitch but I actually use the from scratch way on my website because I understood it better. It will cost $9 to watch the videos and get access to all his other info for a month - that might be a consideration.
Recap: Quick win CanCan or From Scratch if you want to learn more about authorization. Either is good ;-)
Good luck.
Rich
Brandon Barrette
20,485 PointsThanks for the advice. Is rails casts a good site? Seems like there are a lot of good videos on there.
Richard Wigley
3,733 PointsWell, he does plenty of free ones so you can get a handle on the quality. Only the pro and the revised require money.
It's aimed developers who want to get kickstarted on a new gem/technology and for that it's invaluable. I've certainly beneifitted from his work.
He's been very successful but recently he's not produced as much new content. The site says it's $9 will allow you to use the site till September as he feeling the pressure to produce new videos and needs a break. Sounds like a bargin for someone who hasn't used the site!
I do wish him best wishes as every rails developer has benefited from his work.
Rich
Nelson Jimenez
12,061 PointsI recommend to use rolify by roles and cancan for permissions, In the rolify wiki you can find how to use these three gems.
https://github.com/EppO/rolify/wiki/Using-rolify-with-Devise-and-Authority
in rails casts you can learn how to use any gems