开发者

Rails routing error with long class names

开发者 https://www.devze.com 2023-03-25 18:38 出处:网络
I get confused at Rails pluralising and camelcasing. Especially with my long but clear names. I have a User model and an Account model. I also have a user_to_account_log_history model and controller

I get confused at Rails pluralising and camelcasing. Especially with my long but clear names.

I have a User model and an Account model. I also have a user_to_account_log_history model and controller for saving transfers between the two. The relationships are setup.

I ran...

$ rails generate controller UserToAccountLogHistories

...which created the following:

# app/controllers/user_to_account_log_histories_controller.rb
class UserToAccountLogHistoriesController < ApplicationController
  # a simple index method
en开发者_开发问答d

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

My routes seems to be in place (rake routes output, truncated):

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

But I'm getting an uninitialized constant UsertoaccountloghistoriesController. Why? I get the feeling it´s the long names camelcasing and pluralising that messes things up.


The problem is that you have a class called UserToAccountLogHistoriesController but no class called UsertoaccountloghistoriesController -- note the difference in capitalisation here.

It's not clear from your question exactly how you've defined your route, but I suspect that you've got a route referring to usertoaccountloghistories when actually you want to refer to user_to_account_log_histories.

In the rails console, observe the following:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号