# Structure of controllers

**URL:** <https://www.ruby-forum.com/t/structure-of-controllers/85566>\
**Category:** Rails\
**Created:** [February 14, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/structure-of-controllers/85566 "2007-02-14T16:57:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [February 14, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/structure-of-controllers/85566/1 "2007-02-14T16:57:52Z")

</div>

Hi all,

I want to build a website for restaurants. When a user goes to  
[Custom Application Development Software for Business - Salesforce.com](http://www.site.com/restaurants) all the information of that restaurants is  
shown. When he goes to [Custom Application Development Software for Business - Salesforce.com](http://www.site.com/restaurants2), all the info of  
restaurants2 is shown. Eventually I also want to provide other  
functionality than showing info. I’d like to add userlogin per  
restaurant (adding comments, pictures,…).

The problem is that I have a hard time figuring out how to organize my  
controllers. Let’s say I want to add a commenting system (controller  
comment). This would then result in [ww.site.com/comment](http://ww.site.com/comment) although I  
want i to be www.site.be/nameofrestaurant/comment where all the  
comment actions taken are related to nameofrestaurant.

I actually want one code base without the need to copy my code for  
every restaurant that gets added. Is this possible?

Thanks in advance  
Stijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [February 14, 2007, 6:00pm UTC](https://www.ruby-forum.com/t/structure-of-controllers/85566/2 "2007-02-14T18:00:01Z")

</div>

There is no need to make the controller for the comments, just make the  
controllers according to your restaurants and define comments action in  
every controller (related restaurants) so that when there is any comment  
about the restaurant, information will be displayed like  
[www.domain.com/your\_controller\_name/comments](http://www.domain.com/your_controller_name/comments) means  
[www.domain.com/restaurant\_name/comments](http://www.domain.com/restaurant_name/comments)

* * *

Jeniffer F.

> **[firstruby](https://firstruby.wordpress.com/)**
>
> Master ruby with us

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [February 14, 2007, 9:04pm UTC](https://www.ruby-forum.com/t/structure-of-controllers/85566/3 "2007-02-14T21:04:29Z")

</div>

On 2/14/07, Tarscher [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The problem is that I have a hard time figuring out how to organize my  
> controllers. Let’s say I want to add a commenting system (controller  
> comment). This would then result in [ww.site.com/comment](http://ww.site.com/comment) although I  
> want i to be www.site.be/nameofrestaurant/comment where all the  
> comment actions taken are related to nameofrestaurant.

This is the perfect place to take advantage of Rails 1.2’s RESTful  
features.

Check out the PeepCode – [http://peepcode.com/products/restful-rails](http://peepcode.com/products/restful-rails)

It’s cheap and will explain everything you could possibly want to know  
about accomplishing your goal.

–  
Chris W.

> **[err.the\_blog](http://errtheblog.com)**
>
> Err the Blog: Ruby and Rails from the front.
