Can a Rails class name contain numbers? For example:
class Test123
end
Is this a valid class? I get an uninitialized constant Test123 error when I try to load the class.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think Artem Kalinchuk’s last comment deserves to be the answer of this misworded question.
A Ruby class name can contain numbers.
A Rails class has to be defined in a correctly named file. If I define a class called
NewYear2012Controller:Correct file name:
new_year2012_controller.rbIncorrect file name:
new_year_2012_controller.rb(note the extra underscore)Because this is how Rails inflector and auto-loading works.