Forum: Ruby on Rails Namespace & Organisation Conventions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
32ba8c5c148da2653028dc7f8066b810?d=identicon&s=25 Doug Bromley (ashiro)
on 2006-03-08 11:54
(Received via mailing list)
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
Cac068c9c92719a59db960b2fa51719c?d=identicon&s=25 iphan (Guest)
on 2006-03-08 14: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!
32ba8c5c148da2653028dc7f8066b810?d=identicon&s=25 Doug Bromley (ashiro)
on 2006-03-08 16:26
(Received via mailing list)
I've got it all working nicely now.
Thank you so much.  You're a star.
C45aa3228424f6a35ebbfcd7a0e9d801?d=identicon&s=25 Ian White (Guest)
on 2006-03-08 16:50
(Received via mailing list)
> 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
This topic is locked and can not be replied to.