ruby-on-rails – 设计自定义路由无法找到路径的映射?

ruby-on-rails – 设计自定义路由无法找到路径的映射?,第1张

概述我正在尝试设置自定义的facebook身份验证路径,并且我一直都会遇到这个无用的设计错误.它提到我需要为路线设置我的devise_scope,正如你所看到的,我做到了!我无法弄清楚还有什么办法可以让这个错误发挥作用. MyApp::Application.routes.draw doroot :to => 'high_voltage/pages#show', id: 'index'name 我正在尝试设置自定义的facebook身份验证路径,并且我一直都会遇到这个无用的设计错误.它提到我需要为路线设置我的devise_scope,正如你所看到的,我做到了!我无法弄清楚还有什么办法可以让这个错误发挥作用.

MyApp::Application.routes.draw doroot :to => 'high_voltage/pages#show',ID: 'index'namespace :API,defaults: {format: :Json} do  namespace :v1 do    # i've removed all the extra routes for other resources.     # I do not have one for users set up    devise_for :users    devise_scope :user do      post '/users/facebook',to: 'sessions#facebook'    end    get 'users/:ID/events',to: 'users#events'  endendend

我的帖子

myapp[development*] $curl -H 'Content-Type: application/Json' -d '{"auth_token": "12345"}' http://localhost:3000/API/v1/users/facebook

和错误

AbstractController::ActionNotFound at /API/v1/users/facebook============================================================> Could not find devise mapPing for path "/API/v1/users/facebook".This may happen for two reasons:1) You forgot to wrap your route insIDe the scope block. For example:  devise_scope :user do    get "/some/route" => "some_devise_controller"  end2) You are testing a Devise controller bypassing the router.   If so,you can explicitly tell Devise which mapPing to use:   @request.env["devise.mapPing"] = Devise.mapPings[:user]devise (3.1.1) app/controllers/devise_controller.rb,line 84------------------------------------------------------------``` ruby   79       @navigational_formats ||= Devise.navigational_formats.select { |format| Mime::EXTENSION_LOOKUP[format.to_s] }   80     end   81   82     def unkNown_action!(msg)   83       logger.deBUG "[Devise] #{msg}" if logger>  84       raise AbstractController::ActionNotFound,msg   85     end   86   87     # Sets the resource creating an instance variable   88     def resource=(new_resource)   89       instance_variable_set(:"@#{resource_name}",new_resource)```App backtrace-------------Full backtrace-------------- - devise (3.1.1) app/controllers/devise_controller.rb:84:in `unkNown_action!' - devise (3.1.1) app/controllers/devise_controller.rb:59:in `assert_is_devise_resource!' - activesupport (4.0.0) lib/active_support/callbacks.rb:407:in `_run__4085891193320527193__process_action__callbacks' - activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks' - actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action' - actionpack (4.0.0) lib/action_controller/Metal/rescue.rb:29:in `process_action' - actionpack (4.0.0) lib/action_controller/Metal/instrumentation.rb:31:in `block in process_action' - activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument' - activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument' - activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument' - actionpack (4.0.0) lib/action_controller/Metal/instrumentation.rb:30:in `process_action' - actionpack (4.0.0) lib/action_controller/Metal/params_wrapper.rb:245:in `process_action' - activerecord (4.0.0) lib/active_record/railtIEs/controller_runtime.rb:18:in `process_action' - actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process' - actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process' - actionpack (4.0.0) lib/action_controller/Metal.rb:195:in `dispatch' - actionpack (4.0.0) lib/action_controller/Metal/rack_delegation.rb:13:in `dispatch' - actionpack (4.0.0) lib/action_controller/Metal.rb:231:in `block in action' - actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch' - actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call' - actionpack (4.0.0) lib/action_dispatch/routing/mapper.rb:44:in `call' - actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call' - actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call' - actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call' - Meta_request (0.2.8) lib/Meta_request/mIDdlewares/app_request_handler.rb:13:in `call' - rack-contrib (1.1.0) lib/rack/contrib/response_headers.rb:17:in `call' - Meta_request (0.2.8) lib/Meta_request/mIDdlewares/headers.rb:16:in `call' - Meta_request (0.2.8) lib/Meta_request/mIDdlewares/Meta_request_handler.rb:13:in `call' - rack-cors (0.2.8) lib/rack/cors.rb:54:in `call' - warden (1.2.3) lib/warden/manager.rb:35:in `block in call' - warden (1.2.3) lib/warden/manager.rb:34:in `call' - rack (1.5.2) lib/rack/etag.rb:23:in `call' - rack (1.5.2) lib/rack/conditionalget.rb:35:in `call' - rack (1.5.2) lib/rack/head.rb:11:in `call' - actionpack (4.0.0) lib/action_dispatch/mIDdleware/params_parser.rb:27:in `call' - actionpack (4.0.0) lib/action_dispatch/mIDdleware/flash.rb:241:in `call' - rack (1.5.2) lib/rack/session/abstract/ID.rb:225:in `context' - rack (1.5.2) lib/rack/session/abstract/ID.rb:220:in `call' - actionpack (4.0.0) lib/action_dispatch/mIDdleware/cookies.rb:486:in `call' - activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call' - activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call' - activerecord (4.0.0) lib/active_record/migration.rb:369:in `call' - actionpack (4.0.0) lib/action_dispatch/mIDdleware/callbacks.rb:29:in `block in call' - activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__753235512699108649__call__callbacks' - activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks' - actionpack (4.0.0) lib/action_dispatch/mIDdleware/callbacks.rb:27:in `call' - actionpack (4.0.0) lib/action_dispatch/mIDdleware/reloader.rb:64:in `call' - actionpack (4.0.0) lib/action_dispatch/mIDdleware/remote_ip.rb:76:in `call' - better_errors (1.0.1) lib/better_errors/mIDdleware.rb:84:in `protected_app_call' - better_errors (1.0.1) lib/better_errors/mIDdleware.rb:79:in `better_errors_call' - better_errors (1.0.1) lib/better_errors/mIDdleware.rb:56:in `call' - actionpack (4.0.0) lib/action_dispatch/mIDdleware/deBUG_exceptions.rb:17:in `call' - actionpack (4.0.0) lib/action_dispatch/mIDdleware/show_exceptions.rb:30:in `call' - railtIEs (4.0.0) lib/rails/rack/logger.rb:38:in `call_app' - railtIEs (4.0.0) lib/rails/rack/logger.rb:21:in `block in call' - activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged' - activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged' - activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged' - railtIEs (4.0.0) lib/rails/rack/logger.rb:21:in `call' - quIEt_assets (1.0.2) lib/quIEt_assets.rb:18:in `call_with_quIEt_assets' - actionpack (4.0.0) lib/action_dispatch/mIDdleware/request_ID.rb:21:in `call' - rack (1.5.2) lib/rack/methodoverrIDe.rb:21:in `call' - rack (1.5.2) lib/rack/runtime.rb:17:in `call' - activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call' - rack (1.5.2) lib/rack/lock.rb:17:in `call' - actionpack (4.0.0) lib/action_dispatch/mIDdleware/static.rb:64:in `call' - railtIEs (4.0.0) lib/rails/engine.rb:511:in `call' - railtIEs (4.0.0) lib/rails/application.rb:97:in `call' - rack (1.5.2) lib/rack/content_length.rb:14:in `call' - thin (1.6.1) lib/thin/connection.rb:82:in `block in pre_process' - thin (1.6.1) lib/thin/connection.rb:80:in `pre_process' - thin (1.6.1) lib/thin/connection.rb:55:in `process' - thin (1.6.1) lib/thin/connection.rb:41:in `receive_data' - eventmachine (1.0.3) lib/eventmachine.rb:187:in `run' - thin (1.6.1) lib/thin/backends/base.rb:73:in `start' - thin (1.6.1) lib/thin/server.rb:162:in `start' - rack (1.5.2) lib/rack/handler/thin.rb:16:in `run' - rack (1.5.2) lib/rack/server.rb:264:in `start' - railtIEs (4.0.0) lib/rails/commands/server.rb:84:in `start' - railtIEs (4.0.0) lib/rails/commands.rb:78:in `block in <top (required)>' - railtIEs (4.0.0) lib/rails/commands.rb:73:in `<top (required)>' - bin/rails:4:in `<main>'

和控制器

class API::V1::SessionsController < Devise::SessionsController  respond_to :Json  before_filter :authenticate_user!,:except => [:create,:destroy]  skip_before_action :verify_authenticity_token  def facebook  endend

最后我的路线..

API_v1_users_facebook POST   /API/v1/users/facebook(.:format)        API/v1/sessions#facebook {:format=>:Json}

这个错误没有任何意义,因为我已经准确地说明了他们想要的方式,我已经尝试了各种其他解决方案,但是没有工作.

谢谢!

解决方法 我使用RocketPants遇到了类似的问题,但我认为它是等效的.我解决了使用:path_prefix =>在我的情况下’1′,在你的情况下,我会尝试使用:

devise_for :users,:path_prefix => 'API/v1'

请查看此文档https://github.com/plataformatec/devise#configuring-routes

我没有在命名空间中嵌入devise_for

总结

以上是内存溢出为你收集整理的ruby-on-rails – 设计自定义路由无法找到路径的映射?全部内容,希望文章能够帮你解决ruby-on-rails – 设计自定义路由无法找到路径的映射?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1269171.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存