small medium large xlarge

17 Oct 2010, 15:14
Arun Srini (4 posts)

In the cart creation chapter : I declare a scaffold line_item with two integers to hold the relationship between the product and the cart. In the cart controller- I use the symbol ‘:line_items’, no where did I declare or even tell the universe there would be some symbol to denote a line_item. Is this how rails works? a default symbol for models that could be used to store the objects for that model to be used in controllers?? If someone could link me to a blog post explaining this rails character, I’ll be really happy.

19 Oct 2010, 23:33
Sam Wilson (5 posts)

Rails looks at the database schema to determine the basic attributes of the model classes. During its initialization process it looks at the database schema and augments the class definition with the appropriate attributes. You’ll find that you can add additional attributes that are “volatile” (see the part about user authentication for some insight). So, you won’t generally see definitions of each attribute of a model class like you will in other frameworks. Instead, you’ll see various settings applied to those attributes (such as the validations and entity relationships) when they are needed.

By default, however, the model class definitions are empty because they are inferred from the schema.

You must be logged in to comment