且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么此路由在heroku上不起作用,但在本地起作用?

更新时间:2023-01-15 21:22:35

问题是Rails期望模块中的控制器称为 Users ,因为这就是 namespace:user 的推断。也许您是想使用 scope 而不是 namespace

The problem is that Rails is expecting there to be a controller within a module called Users because that's what namespace :user infers. Perhaps you meant to use scope instead of namespace?

scope :path => "user" do
  root :to => "users#profile"
end

注意:在这种情况下,如果您只有一种方法,使用 scope 并不明智,但是如果您有多个带有 / user 前缀的那么就可以了如果您只有一个,我会改为:

Note: in this situation if you've only got one route it would not be wise to use scope, but if you've got multiple ones with the /user prefix then it would be fine to. If you only had one, I would do this instead:

get '/user', :to => "users#profile"