Rails Flashcards
What types of associations can models have in RoR?
belongs_to
has_one
has_many
has_and_belongs_to_many
polimorphic
self joins
What’s a gem?
Packaged Ruby code, ready to be reused across projects.
What does MVC stand for?
Model View Controller
What’s the naming convention for models in Rails?
Singular, camel-cased nouns.
E.g. BookClub
What’s the naming convention for tables in Rails?
Pluralized, snake-cased nouns.
E.g. book_clubs
What’s the naming convention for controllers in Rails?
Pluralized, camel-cased nouns, suffixed with the term “Controller”.
E.g. BookClubsController
What’s a callback in the context of RoR?
It’s a method that gets called at certain moments of an object’s life cycle (e.g. when an Active Record object is created, saved, updated, deleted, validated, or loaded from the database).
What does ORM stand for?
Object Relational Mapping
What is Object Relational Mapping?
It is a technique that connects objects to tables in a relational database.
Using ORM, the properties and relationships of the objects in an application can be easily stored and retrieved from a database without writing SQL statements directly.
What’s Active Record?
Active Record is Ruby on Rails’ ORM framework.
What does “convention over configuration” mean?
Rails has a set of conventions (naming conventions and schema conventions); if you follow them, you’ll spare yourself from writing configuration code.
E.g. If your model is named “BookClub”, Rails will expect it to be related to a table named “book_clubs”; respecting that convention will keep your code free from configuration code.
What is “eager loading?
It’s a mechanism for loading associated records more efficiently.
Which methods does RoR provide for eager loading?
includes
preload
eager_load
What’s wrong with this code?
Project.where("name = '#{params[:name]}'")
It’s vulnerable to SQL injection.
How can you access sensitive credentials in RoR?
Rails.application.credentials