美文网首页
3. REST, Resources, and Rails -

3. REST, Resources, and Rails -

作者: 介可能是只乌龟 | 来源:发表于2016-04-03 22:57 被阅读0次

    3.6 Singular Resource Routes

    In addition to resources, there’s also a singular (or singleton) form of resource routing: reso urce.It’s used to represent a resource that only exists once in its given context.

    A singleton resource route at the top level of your routes can be appropriate when there’s only one resource of its type for the whole application, perhaps something like a per-user profile.

    resource :profile
    

    You get almost the full complement of resource routes, all except the collection route (index). Note that the
    method name resource
    , the argument to that method, and all the named routes generated are in the singular.

    It’s assumed that you’re in a context where it’s meaningful to speak of the profile—the one and only—because there’s a user to which the profile is scoped. The scoping itself is not automatic; you have to authenticate the user and retrieve the profile from (and/or save it to) the database explicitly. There’s no real magic or mind-reading here; it’s just an additional routing technique at your disposal if you need it.

    相关文章

      网友评论

          本文标题:3. REST, Resources, and Rails -

          本文链接:https://www.haomeiwen.com/subject/ywpulttx.html