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
Admin User the lazy way?
I've built user logins (plus relevant associations) for a site, and the next step is to create a page that only the site owner can post to (but users can read).
I've used the Sorcery gem for building user logins, which has worked well so far (Devise seemed to be a bit TOO bulky and OTT for my needs - hope I don't come to regret that decision!).
From briefly reading a few forum posts about how to create 'admins', I had an idea that I'd like to run past people before committing to it:
Rather than creating a 'true' 'admin', why don't I just make sure the website owner is the first person to register on the site, having set permissions and associations based on a user_id of 1? I'm not sure how exactly to go about that yet, but I'm sure it wouldn't be very difficult?
Maciej Czuchnowski36,441 Points
If you want to do it your way and you're sure you only want one admin user (with id of 1), then it's a simple before_action in the controller with code like "redirect_to some_page_path unless current_user.id == 1" for selected actions available only for that user. Brandon's link is very cool, I will surely build a training app for myself to try to implement it. If you want something heavier, then check out Pundit gem.
Brandon Barrette20,485 Points
I'd read this blog post about the introduction of enums in Rails 4.1:
It gives you many helpers to ask
Yes, that 'enums' thing is VERY cool! I might implement that into my current build.