i have a newbie question. been playing around with RoR for a while
now, but finally building an application for public usage. my question
concerns how to create an admin section and a public section of the
website/application. for instance, i want an admin section which lets
the owners of the site log and make changes. i'm wondering do i need
multiple controllers with authentication turned on (i'm using a
standard example, which uses a before_filter on controllers that
require login) for admin and separate controllers to be used by the
public pages? i'm not sure if i'm explaining this correctly. here's a
list of things i'm trying to accomplish:
Models:
food
categories
events
Admin Controllers/pages:
food
categories
events
public pages (separate controllers and views needed?:
food (sorted by categories)
events
and if i do need separate controllers and views, do i link them to the
shared models using custom Routes?
The other option is to use in-place editing, where the actual option
to click on a field and edit it only exists
if you're an admin/authorized. It actually cleans up controller code a
bit. That's how I solved this problem.
The third option is to use different layouts and templates based on if
they are logged in. This lets you completely customize the look for
admins while maintaining basically the same controllers.
that's probably more what i was thinking. so where do you do the check
for login? in the controller for each model/view? right now, i'm doing
a before_filter to call my authenticate action. i'm thinking i have to
move that somewhere else? how would i go about that? thanks
These are all cut/paste from the peepcode code. I highly recommend
them. For $9, its the best training on rails available... either than
RailsCasts.com
so i figured out what i really wanted to do. i've been stuck in the 1
Model : 1 Controller : 1 View mindset. when today, i thought, why not
create a different controller and view pair for each public website
section i want. is this frowned upon or a perk of the MVC pattern?
I'd highly recommend using namespaces so you can have a separate
controller/views. For the layout (I use just a single admin layout),
create a switch method in your application controller:
layout :set_layout
def set_layout
params[:controller] =~ /^admin/ ? 'admin' : 'public'
end