我正在使用Rails,iOS和设计。我想读一个用户。路径为users /:id。
我收到以下错误:
Started GET "/users/0" for 127.0.0.1 at 2012-06-11 17:37:50 -0600
Processing by UsersController#show as JSON
Parameters: {"id"=>"0"}
[Devise] Could not find devise mapping for path "/users/0".
Maybe you forgot to wrap your route inside the scope block? For example:
devise_scope :user do
match "/some/route" => "some_devise_controller"
end
Completed 500 Internal Server Error in 0ms
AbstractController::ActionNotFound (Could not find devise mapping for path "/users/0".
Maybe you forgot to wrap your route inside the scope block? For example:
devise_scope :user do
match "/some/route" => "some_devise_controller"
end
我尝试过放置资源:devise_for:users下面的用户以及获取“users /:id”=> “users#show”并匹配“users /:id”=> “用户#显示”。
有什么想法吗?
答案 0 :(得分:1)
这是我的最终解决方案:
devise_for :users, :controllers => { :registrations => "users"}
devise_scope :user do
get "users/:id" => "users#show"
end
答案 1 :(得分:0)
查看名为“配置路线”的文档部分:
https://github.com/plataformatec/devise#readme
答案也部分包含在错误消息中。
至于为什么devise_for似乎胜过routes.rb
中该行以下的路线,请查看指南:
http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions
Rails路由按照指定的顺序进行匹配,所以如果你 有一个资源:上面的照片得到'照片/民意调查'的节目动作 资源行的路由将在获取行之前匹配。至 解决这个问题,将get行移到资源行上方,这样就可以了 首先匹配。