at.
at.

Reputation: 52530

Convention for ActiveRecord model names

What is the naming convention for models in Rails? If my model is about flying cars, which of the following class names is most appropriate?

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

Upvotes: 2

Views: 350

Answers (2)

RyanWilcox
RyanWilcox

Reputation: 13972

Your model class name must be PascalCase (FlyingCar) and it must be singular.

For controller classes it's PascalCase, plural, and ends with Controller (so: FlyingCarsController)

Upvotes: 1

Doug R
Doug R

Reputation: 5779

FlyingCar is the Ruby convention. This becomes even more important when ActiveRecord is trying to do its magic. There's ways you can override this behavior, but using FlyingCar is what ActiveRecord expects.

Upvotes: 5

Related Questions