为什么此路由在heroku上不起作用,但在本地起作用? [英] why doesn't this routing work on heroku but works locally?

查看:116
本文介绍了为什么此路由在heroku上不起作用,但在本地起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的route.rb文件中,有 Rails 3

I have the following in my routes.rb file for Rails 3:

 13   namespace :user do
 14     root :to => "users#profile"
 15   end

我在heroku上收到此错误:

I get this error on heroku:

ActionController::RoutingError (uninitialized constant User::UsersController):

我已经重新启动了应用程序。

I already restarted the application.

我这样做是因为我正在使用devise,这就是它所说的Wiki:

I am doing this because I am using devise and this is what it says on the wiki:

https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-登录

推荐答案

问题是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"

这篇关于为什么此路由在heroku上不起作用,但在本地起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆