# Newb question

**URL:** <https://www.ruby-forum.com/t/newb-question/98089>\
**Category:** Rails\
**Created:** [July 12, 2006, 3:11pm UTC](https://www.ruby-forum.com/t/newb-question/98089 "2006-07-12T15:11:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 12, 2006, 3:11pm UTC](https://www.ruby-forum.com/t/newb-question/98089/1 "2006-07-12T15:11:51Z")

</div>

I already have AWDWR and have done a number of tutorials , so it’s okay  
to  
refer me to those however I’d prefer, if there is a semi-simple answer  
to  
this to perhaps offer one up.

I want to build a site that will work around “role based” authentication  
and  
I’m thinking about it in relation to my directory structure.  
so the roles might be:  
company  
group  
user-gold  
user-silver

would I build a directory structure like:  
company/index  
company/do\_something  
company/do\_something\_else

group/index  
group/do\_something  
group/do\_something\_else …

usergold/index  
usergold/do\_something  
… and on

if this makes sense , do I then make controllers for each page ? i.e:  
generate controller company index  
generate controller company do\_something\_else  
generate controller usergold do\_something

Or am I totally missing something here ?  
Hope I made the question clear enough.  
Appreciate any explanation  
TIA  
Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 12, 2006, 4:24pm UTC](https://www.ruby-forum.com/t/newb-question/98089/2 "2006-07-12T16:24:11Z")

</div>

If you haven’t already, watch the blog demo video:  
[http://media.rubyonrails.org/video/rails\_take2\_with\_sound.mov](http://media.rubyonrails.org/video/rails_take2_with_sound.mov)

Is a great tutorial that may help you understand  
controllers/directories.

Your controller names will show up in your URLs, so you should pick  
controller names that make sense like: login (holds all your login  
login), users (holds your user logic), groups (etc etc).

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 12, 2006, 4:53pm UTC](https://www.ruby-forum.com/t/newb-question/98089/3 "2006-07-12T16:53:27Z")

</div>

On 12/07/06, David C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Your controller names will show up in your URLs, so you should pick  
> controller names that make sense like: login (holds all your login  
> login), users (holds your user logic), groups (etc etc).

No, your controller names will show up in your URLs _by default_. This  
can, of course, be changed in routes.rb.

As regards structuring your app: I don’t think you need a seperate  
controller for each level of access. You might want to seperate out  
(say) an administrative/corporate backend from a user-facing front  
end, though.

To give you an example based on what you’ve given us: why do you need  
a user-gold controller and a user-silver controller? Why not just have  
a user controller, store the user’s access level in a cookie/session,  
and then display content conditionally dependent on their status?

Using a controller for each access level will lead to lots of  
repetition. In this case, that’s a bad thing.

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 12, 2006, 5:41pm UTC](https://www.ruby-forum.com/t/newb-question/98089/4 "2006-07-12T17:41:36Z")

</div>

On 7/12/06, Tom A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> To give you an example based on what you’ve given us: why do you need  
> a user-gold controller and a user-silver controller? Why not just have  
> a user controller, store the user’s access level in a cookie/session,  
> and then display content conditionally dependent on their status?
> 
> Probably don’t need seperate ones. I’ll narrow it down for the moment so  
> perhaps my confusion can be cleared up:  
> so usergold after logging in goes to  
> usergold/index (from there there are links and perhaps some of their  
> account  
> information)  
> the links might be  
> usergold/searcharticles  
> usergold/postarticles  
> usergold/checkforum  
> usergold/upgrade

I guess, the way it works is all the code is in the usergold controller  
and  
then each function has it’s methods and within those functions  
information  
about the correct view to pull up ?

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 12, 2006, 6:10pm UTC](https://www.ruby-forum.com/t/newb-question/98089/5 "2006-07-12T18:10:55Z")

</div>

> so usergold after logging in goes to  
> usergold/index (from there there are links and perhaps some of their  
> account information)  
> the links might be  
> usergold/searcharticles  
> usergold/postarticles  
> usergold/checkforum  
> usergold/upgrade

This is really not a cool idea IMO. What Tom suggested is the way to  
go. Create your controllers to handle the content and protect using  
filters. Your controllers should look something like:

user/  
articles/search/  
articles/post/  
forums/1/  
memberships/upgrade/

Steve

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 12, 2006, 6:33pm UTC](https://www.ruby-forum.com/t/newb-question/98089/6 "2006-07-12T18:33:38Z")

</div>

> I guess, the way it works is all the code is in the usergold controller and  
> then each function has it’s methods and within those functions information  
> about the correct view to pull up ?

Maybe. Let’s get the terminology right, though, for clarity:

if there’s some conditional data, you might want to put some  
conditional statements into each action in the controller so that only  
the necessary data is passed to the view. You could then put  
conditional statements in the view to show extra stuff for certain  
classes of users.

Alternatively, if there are some pages that only a “gold” user might  
see, then it might be worth making seperate views for those, and then  
putting the call to render that view in a conditional statement on the  
controller. Does that make sense?

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 12, 2006, 7:47pm UTC](https://www.ruby-forum.com/t/newb-question/98089/7 "2006-07-12T19:47:45Z")

</div>

On 7/12/06, Tom A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> the necessary data is passed to the view. You could then put  
> conditional statements in the view to show extra stuff for certain  
> classes of users.

Okay I understand that and have done that similarly in PHP (not to  
dredge up  
that beast :))  
As well, blocked entire pages based on the access level of the user.

Alternatively, if there are some pages that only a “gold” user might

> see, then it might be worth making seperate views for those, and then  
> putting the call to render that view in a conditional statement on the  
> controller. Does that make sense?

Yes, it makes sense. Unfortunately I am still stuck back at part of my  
original question, but will ask it again in a revised form in light of  
these  
clarificaitons -  
Should I just forget about the idea of “directories” when designing in  
ROR  
?

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 12, 2006, 11:23pm UTC](https://www.ruby-forum.com/t/newb-question/98089/8 "2006-07-12T23:23:02Z")

</div>

Thanks Dan, just got done reading about routing and also the section in  
AWDWR. I see the point though in coming back after the controllers are  
set  
up.

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [July 12, 2006, 8:03pm UTC](https://www.ruby-forum.com/t/newb-question/98089/9 "2006-07-12T20:03:38Z")

</div>

Create your controllers based on the actions that users will be  
doing. Then, separately, construct your urls using routes to have  
the “directories” look however you want them to.

e.g.: map.connect ‘:year/:month/:day’, :controller =\>  
‘blog’, :action =\> ‘by\_date’

For a simple app, you should easily be able to have a number of  
controllers, each with a number of actions, without needing any more  
hierarchy in your controller directory. What you expose to users is  
entirely independent.

[http://manuals.rubyonrails.com/read/chapter/65](http://manuals.rubyonrails.com/read/chapter/65)

New question: what happened to the API docs for  
ActionController::Routing?  
[http://api.rubyonrails.com/](http://api.rubyonrails.com/)

```
        - dan

```

–  
Dan K. [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.dankohn.com/](http://www.dankohn.com/)tel:+1-415-233-1000
