2

Rails中模型的命名约定是什么?如果我的模型是关于飞行的汽车,那么下列哪个类名是最合适的?ActiveRecord型号名称约定

class FlyingCar < ActiveRecord::Base 
    attr_accessible :model, :max_speed 
end 

class Flying_Car < ActiveRecord::Base 
    attr_accessible :model, :max_speed 
end 

class Flying_car < ActiveRecord::Base 
    attr_accessible :model, :max_speed 
end 

回答

5

FlyingCar是Ruby的惯例。当ActiveRecord试图发挥它的魔力时,这变得更加重要。有许多方法可以覆盖此行为,但使用FlyingCar是ActiveRecord的期望。

1

您的模型类名称必须是PascalCase(FlyingCar)它必须是单数。

对于控制器类是PascalCase,复数,用的控制器端(这样:FlyingCarsController)

+0

谢谢大家的更详细的解答 –