【问题标题】:Rails route for api on subdomain子域上 api 的 Rails 路由
【发布时间】:2012-07-30 12:46:18
【问题描述】:

我想让我的 Rails 应用程序的 API 可以通过子域 (https://api.domain.com) 访问。我定义了以下路线:

constraints :subdomain => 'api' do
  namespace :api, defaults: {format: 'json'} do
    scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do
      resources :posts
    end
  end
end

这可行,但会产生以下网址:

https://api.domain.com/api/posts

我希望它是:

https://api.domain.com/posts

API 控制器位于 app/controllers/api/v1 中它们应该保留的位置。

我尝试绘制路线但没有成功。有人知道如何解决这个问题吗?

【问题讨论】:

    标签: api routes subdomain ruby-on-rails-3.2


    【解决方案1】:

    改变

    namespace :api, defaults: {format: 'json'} do
    

    namespace :api, path: nil, defaults: {format: 'json'} do
    

    【讨论】:

      猜你喜欢
      • 2013-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-09
      • 2014-02-27
      • 2011-11-01
      相关资源
      最近更新 更多