2011-08-04 82 views
0

我对Rails的多元化和驼峰感到困惑。尤其是我长而清晰的名字。导致类名长的路径错误

我有一个User模型和一个Account模型。我也有一个user_to_account_log_history模型和控制器来保存两者之间的转移。关系是建立的。

我跑......

$ rails generate controller UserToAccountLogHistories 

...这创造了以下内容:

# app/controllers/user_to_account_log_histories_controller.rb 
class UserToAccountLogHistoriesController < ApplicationController 
    # a simple index method 
end 

# app/models/user_to_account_log_history.rb 
class UserToAccountLogHistory < ActiveRecord::Base 
end 

我的路线似乎是在地方(rake routes输出,截断):

user_usertoaccountloghistories GET /users/:user_id/usertoaccountloghistories(.:format) {:action=>"index", :controller=>"usertoaccountloghistories"} 

但我收到uninitialized constant UsertoaccountloghistoriesController。为什么?我感觉这是一个漫长而漫长的过程,会让整件事情混乱起来。

回答

1

问题是你有一个名为UserToAccountLogHistoriesController的类,但没有叫UsertoaccountloghistoriesController的类 - 请注意这里的大小写的区别。

从您的问题确切地说明您是如何定义您的路线的,但我怀疑您实际上想要参考user_to_account_log_histories时有一条路线指的是usertoaccountloghistories

在轨控制台,注意以下事项:

> "hello_world".camelize 
# => "HelloWorld" 
> "helloworld".camelize 
# => "Helloworld" 
+0

谢谢!我没有下划线进入路线。 –

相关问题