Test rails 1 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is Active Record in Rails?

A

Active Record is the Object-Relational Mapping (ORM) layer in Rails that allows developers to interact with the database using Ruby objects. It automatically maps tables to classes and rows to instances of those classes. It provides methods for creating, reading, updating, and deleting records without needing SQL. Active Record also supports associations between models, validations, and callbacks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain belongs_to in Rails.

A

belongs_to defines a one-to-one connection between two models, where one model contains the foreign key of another. This association is typically used when a child model references a parent model. For example, if a Post belongs to a User, the posts table will have a user_id column that points to the users table. Rails automatically provides helper methods for accessing the associated user from a post.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does self refer to in Ruby?

A

self in Ruby refers to the current object on which a method is being executed. Within an instance method, self points to the instance of the class. Inside a class method, self refers to the class itself. Understanding self is crucial for distinguishing between class methods and instance methods, and for writing methods that modify the current object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly