Ruby / Rails naming conventions
naming-conventions, ruby, ruby-on-rails
Solution
The only reserved word is capitalized `Product` and this references the object model. For example to get all products and save it in the variable `@products` you would do:
@products = Product.all
@product = Product.find(1)
If you left off the `@` sign off of 'products' then it would be saved only as a local variable and your view would not be able to access it.
In this example `@products` and `@product` are variables you declare in the controller. You could just use:
@lotsofproducts = Product.all
Problem
If I generate a scaffold called `"product"`, what are the differences between the following when I use them in coding my app? `@products`, `@product`, `@Product`, `@Products`, `Products`, `Product`, `product`, and `products` (I'm pretty sure those aren't all used, but it should at least give the idea of what I'm referring to). I can't seem to find a simple explanation of what each combination of `@`/capitalization/plurality means. Help would be greatly appreciated.