SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Once I was a Factory Worker goofy's Avatar
    Join Date
    Dec 2004
    Location
    Sydney Australia
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Model and Controller Names

    Just wondering what is recommended for model and controller names. For example, i want to build a site for that has car sales so I might want to call my controller 'cars_for_sale'. I would want something like this because it's more descriptive than say 'classifieds' and would work better for readability in the URL.

    Can I call my controller car_sales and if so how will this affect rails conventions of using the singular controller name when creating controllers and models.

    Any suggestions would be appreciated.
    Goofy
    Life is what you make it!
    Follow your dreams!

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is probably easiest to start by defining your models before you start thinking about your controllers. So start by defining the objects you are modelling.

    For example, if you decide that all you have are cars and that when sold all that happens is that a property status changes to sold then I think the convention would point towards you calling the controller "cars" and then you having a "for_sale" view that would list all cars where the status is not sold.

    However, if you find that "a sale" is itself an object (perhaps mimicing an invoice or sales note) and therefore you have car and sale objects, things get a little more complicated. By convention I think you'd probably then have a sales and a cars controller depending which object you were providing view or actions upon.

    Which ever way, if you needed a "/cars_for_sale" URL, you'd create a route that would direct the system to the relevant controller and view. Therefore, the desired URL does not have to dictate the controller name.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •