[Rails] (resend - sorry!) Which controllers?

Tony Mobily merc at mobily.com
Mon Feb 27 05:01:50 GMT 2006


Hi,

First of all: thanks a lot for your answer!

> You should get the Agile Rails Book, and read it too :)

Wooops... I am up to page 100 with that one!
(And I still don't get it. Shame on me!)

> Creating a logical controller structure if pretty darn easy... for  
> instance, some of my controllers are:
> admin_controller.rb, animal_controller.rb, blog_controller.rb

OK!
My "problem" is that I don't get when it makes sense logically to  
create a controller.
Is it meant to control the contents of a specific table?
For example, if I create the controller "user", I would like these  
URLs to work:

/user/merc/blog/ (controller is "user", ID is "merc", action is "blog"
/user/merc/gallery
/user/merc/friends_and_foes
/user/merc/leave_message

This is for the front-end. Does creating such a controller make  
sense? This controller wouldn't manage a specific table. It would  
fetch data from several tables, for the user.

As far as the back-end, shall I have one controller per  
functionality? Or one controller to manage lock, stock and barrel?
For example, do I want to create a controller "backend", which does:

/backend/blogs <--- Show the blog entries. Action:
/backend/blog_entry_add <--- Add a blog entry
[...]
/backend/images_list <---- Show the list of images
/backend/image_upload <---- Allow the upload of an image

Or shall I create several controllers?
Like this:

/blog/merc/list (controller "blog", ID "merc", action "list")
/blog/merc/add
/blog/merc/delete
/blog/merc/edit
[...]
/images/merc/list (controller "images", ID "merc", action "list"
/images/merc/add
/images/merc/delete
/images/merc/edit
[...]

Then, I can use the route mechanism to reroute things so that I can do:

/backend/blog/merc/add (controller "blog", ID "merc", action "add")

So that I keep the URLs clean.

Would this make sense?

What's the philosophy of what controllers should be there? What is a  
controller from a "logical" point of view? Shall I think of a  
controller as a module that deals with one specific table?

Thanks a million and bye!

Merc

> It all makes sense when you read the book, and most importantly,  
> start getting your hands dirty creating your application !
>
> Have fun too !
> ==
> Dylan
>
>
> On 2/26/06, Tony Mobily <merc at mobily.com> wrote: Hello,
>
> I have recently started learning RoR. I think it's _fantastic_. I am
> absolutely blown away.
> OK, this is to prepare you to my idiotic question. Hopefully, I won't
> be stoned.
>
> I am designing a simple application, where users can register, and:
>
> * Publish a photo album
> * Publish a simple blog with comments
> * Determine their list of friends and foes
>
> The application will obviously have a front end and a backend.
> The front end will give people a chance to search, and "find" members
> and blogs
> The back end will allow people to manage their profiles and add blog
> entries.
>
> Now: I like the idea of urls like this:
>
> domain.com/user/merc/blog
>
> Where:
> * "user" is the controller
> * "merc" is the user id
> * "blog" is the action (in this case, show the blog)
>
> The backend could be:
>
> domain.com/backend/merc/blog
>
> Where everything is as above, a part from the fact that "backend" is
> the controller.
>
> This does mean that each controller will have quite a few actions.
>
> I guess my question is: how do you decide what a "controller" is and
> does? How should I divide the application amongst several controllers?
>
> Well... I hope I didn't embarrass myself too much.
>
> Thanks a lot and bye!
>
> Merc.
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails


More information about the Rails mailing list