首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >子域-fu不在rails 4中工作

子域-fu不在rails 4中工作
EN

Stack Overflow用户
提问于 2015-10-15 10:14:37
回答 2查看 201关注 0票数 1

在我的创业板文件中,我添加了创业板'subdomain-fu', '1.0.0.beta2'。然后我做了bundle install。我试图打印<%= current_subdomain %>,但得到了undefined local variable or methodcurrent_子域‘’。我为什么要犯这个错误?

我也重新启动了我的nginx服务器和独角兽。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-15 10:36:02

您不需要创业板来在Rails中添加sudomains。

这是一些代码,我已经成功地添加到我的一个应用程序。

routes.rb中添加以下内容:

代码语言:javascript
复制
constraints subdomain: false do
  root to: 'landings#index'
end

constraints subdomain: 'my' do
  get '/', to: 'users#show', as: 'app_root'

  resources :users
  resources :games do
    collection do
      get :search, to: 'games#search', as: :search
    end
  end
end

以下是我的看法:

代码语言:javascript
复制
                root GET    /                                                              landings#index
            app_root GET    /                                                              users#show {:subdomain=>"my"}
               users GET    /users(.:format)                                               users#index {:subdomain=>"my"}
                     POST   /users(.:format)                                               users#create {:subdomain=>"my"}
            new_user GET    /users/new(.:format)                                           users#new {:subdomain=>"my"}
           edit_user GET    /users/:id/edit(.:format)                                      users#edit {:subdomain=>"my"}
                user GET    /users/:id(.:format)                                           users#show {:subdomain=>"my"}
                     PATCH  /users/:id(.:format)                                           users#update {:subdomain=>"my"}
                     PUT    /users/:id(.:format)                                           users#update {:subdomain=>"my"}
                     DELETE /users/:id(.:format)                                           users#destroy {:subdomain=>"my"}
        search_games GET    /games/search(.:format)                                        games#search {:subdomain=>"my"}
               games GET    /games(.:format)                                               games#index {:subdomain=>"my"}
                     POST   /games(.:format)                                               games#create {:subdomain=>"my"}
            new_game GET    /games/new(.:format)                                           games#new {:subdomain=>"my"}
           edit_game GET    /games/:id/edit(.:format)                                      games#edit {:subdomain=>"my"}
                game GET    /games/:id(.:format)                                           games#show {:subdomain=>"my"}
                     PATCH  /games/:id(.:format)                                           games#update {:subdomain=>"my"}
                     PUT    /games/:id(.:format)                                           games#update {:subdomain=>"my"}
                     DELETE /games/:id(.:format)                                           games#destroy {:subdomain=>"my"}

这个方法的缺点是,对于子域路由,必须使用search_games_path(subdomain: 'mysubdomainname')search_games_url (which automatically points to your subdomain)

票数 2
EN

Stack Overflow用户

发布于 2015-10-15 10:36:51

Rails 4附带内置的功能,所以您不需要使用诸如subdomain_fu这样的老宝石。

要获取rails 4中的当前子域,只需执行以下操作:

代码语言:javascript
复制
<%= request.subdomain %>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33145795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档