Hi All I wanted a little advice on the convention for namespace usage and organisation of code. I originally used PHP and often had an "admin" backend that performed the various admin tasks with users, and data Then I had a front-end often situated at the root that had user services. I'm trying to emulate this in Rails but feel I'm missing a significant point here and I'm using PHP programming methods on Rails and it doesn't feel right. Is it better to filter a users view dependent on their status rather than have different namespaces for each user type? I'd very much appreciate your guidance as my code is becoming messy and I'm becomig increasingly confused as I'm having 3 controllers of the same name but different namespaces. Kind regards Doug
on 2006-03-08 12:54
on 2006-03-08 15:52
Hello Doug, have you tried the recipes from the rails wiki? http://wiki.rubyonrails.com/rails/pages/Authentication this worked fine for me; I have 3 controllers: - LoginController with only the index and authenticate methods. - AdminController to administrate users. - MyApplicationController, starting with the line: before_filter :authenticate, :only => [ :new, :create, :edit, :update, :destroy ] I use roles to define user types. I did it very simply by adding an attribute 'role' to the Person object, but you can also define a proper Role object. My AdminController ends with: protected def authenticate unless @session["person"] and (@session["person"].role == "admin") flash[:notice] = "You need to login as administrator first" redirect_to :controller => "login" return false end end best regards and good luck!
on 2006-03-08 17:26
I've got it all working nicely now. Thank you so much. You're a star.
on 2006-03-08 17:50
> I originally used PHP and often had an "admin" backend that performed the > various admin tasks with users, and data > Then I had a front-end often situated at the root that had user services. On my current project there's only a couple of controllers that are the user servcies, and many that are admin tasks. So I set up the routes in routes.rb in a way similar to this: map.connect '', :controller => "home" map.connect 'userservice1/:action/:id', :controller => 'userservice1' map.connect 'admin/:controller/:action/:id' That way you need to give uri's like admin/myproduct/list to get to the 'admin' controllers Cheers, Ian