我有一个资源profile,我希望用户能够以各种方式访问它。我希望登录用户能够从这些路由访问他们自己的配置文件:
GET /profile
GET /profile/edit
PATCH /profile
PUT /profile我希望通过这条路线可以看到个人资料:
GET /profiles/:id无法创建或删除配置文件,用户也不能编辑其他用户的配置文件。我也不希望向用户公开配置文件索引,因此这些路由都不应该可用:
GET /profile/new
POST /profile
DELETE /profile
GET /profiles
GET /profiles/:id/edit
PATCH /profiles/:id
PUT /profiles:id
DELETE /profiles/:id
GET /profiles/new
POST /profiles我正在使用这个路径映射:
resources :profiles, only: [:show]
resource :profile, only: [:show, :edit, :update]两个问题:
/profile/edit上提交表单时,它试图修补到/profiles/:id,这是无效的。它似乎应该修补到/profile。我做错了什么?发布于 2013-12-20 20:18:51
如果您使用像resource :profile, only: [:show, :edit, :update]这样的单例资源,它假定整个应用程序只有其中一个资源。
如果您真的认为用户必须拥有这些路由,只需将它们映射到它们所属的位置即可。
resources :profiles, only: [:show, :edit, :update]
get '/profile', to: 'profiles#show'
...https://stackoverflow.com/questions/20709547
复制相似问题