Ruby on Rails Resource Design, singular vs. plural

I'm still learning Rails and how to best design my resource structure. Could someone help me with this? Here's my problem:

I am designing a specialized social network with profiles - every account has one profile. At the moment, an Account stores basic info about the user (username, password, etc.) from when they first sign up. A Profile stores other thinks like a picture link, answers to personality questions (linked back to a Profile via foreign key), and maybe more in the future. There is a one-to-one relationship between Account and Profile. Users can view/edit their own profile and view profiles belonging to others.

My questions:

  • Is it a good idea to split these two into separate resources altogether (ie have two different models) or collapse them into one model with two controllers? I have tried the latter, and it almost seems like more trouble than it's worth. Am I, in this case, fighting against the framework? I'm not sure yet whether users should be able to have more than one account in the future.

  • If I do split them, should I use a singular or plural resource for the profile? I noticed in the language at guide.rubyonrails.org that get (show) and put (update) work with the ONE and ONLY profile resource. My question with respect to my current situation is: "one and only" with respect to what? The "one and only" profile for the current user's account or with respect to the entire site? If so, how could I have the current user view profiles of other users - should I use a URL parameter like so:

  • http://www.example.com/profile?id=x, where x is the other user's account id

    If I go the plural route, does index showing "all profiles" intend to mean all for the current user or for everyone across the site? Or is this up to my own interpretation?

    I would appreciate any help I can get with this, as I feel like I am starting to understand REST and RoR conceptually but am just trying to put it into practice. Thanks!


    I would personally keep Account and profile as two separate resources or at the lest 2 separate controllers accessing different parts of the same model. This allows easy routes like http://www.example.com/profiles/2 for viewing other users and http://www.example.com/accounts/2 for managing your own account without having to add custom routes.

    If you have the possibility of adding more profiles to an account, then this is a form of future proofing too.

    链接地址: http://www.djcxy.com/p/41320.html

    上一篇: 用https post发送python上传字符串

    下一篇: Ruby on Rails资源设计,单数还是复数