【问题标题】:Rails 5, Route declare but not foundRails 5,路由声明但未找到
【发布时间】:2016-04-23 14:20:35
【问题描述】:

在我的路线配置中,我有:

constraints subdomain: 'api' do
    scope module: 'api' do
        namespace :v1 do
            get '/me', to: 'users#me'
        end
    end
end

bin/rake 路由返回

v1_me GET    /v1/me(.:format)     api/v1/users#me {:subdomain=>"api"}

当我尝试使用邮递员使用 uri http://localhost:3000/v1/mehttp://localhost:3000/api/v1/mehttp://localhost:3000/me 时,出现 404 not found 错误。

 ActionController::RoutingError (No route matches [GET] "/v1/me"):

我的代码有什么问题?

【问题讨论】:

    标签: ruby-on-rails ruby


    【解决方案1】:

    您为子域设置了约束。 因此,您必须通过api.localhost:3000 之类的方式访问它 对于任何开发环境来说,这都不是开箱即用的。

    您的路由确保仅为api 子域定义指定的端点。

    你可以试试这些:

    http://api.lvh.me:3000

    http://api.localhost:3000

    您可能需要在主机文件中添加条目以将任何自定义域指向127.0.0.1

    【讨论】:

      【解决方案2】:

      您可以使用子域访问本地主机,例如http://api.lvh.me:3000/

      所以你的网址变成了http://api.lvh.me:3000/api/v1/me

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-01
        • 2017-08-19
        • 2015-06-26
        • 2019-07-18
        • 1970-01-01
        • 2020-07-23
        • 2022-11-03
        • 1970-01-01
        相关资源
        最近更新 更多