SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Controller/RESTful..?

    Hello. I'm coming from a non MVC background, mainly C and PHP - I'm wondering how the Controllers and RESTful framework deal with this:

    In PHP, a URL would have both a view and an action in them, such as:

    www.app.com/view.php?action=edit
    -
    ..which tells the app what view we're in, and what's the action.

    but in RoR it's

    www.app.com/controller/action
    -
    ..does this mean that I need as many controllers as pages?

    How do you usually deal with this? how does the controller know which view to display? Seeing as a similar action could come from several different views?

    Alex

  2. #2
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    The controller is the class. The action is the class methods. So, in general, you would need as many methods for the class "controller" as actions. From there you can refactor simple and/or repetitive actions.
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  3. #3
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand that, but say for example, I would like to have a view which has both listing and editing, how is the controller set up?

    Or say I have a view which displays several different Models, does that mean I should have one controller per view? But if that's the case, won't I have repeated code if there are several places to edit/view the same data?


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
  •