Câu hỏi phỏng vấn Ruby on Rails
Câu hỏi

What Things We Can Define In The Model?

Câu trả lời

Here are some of the key things you can define in a Ruby on Rails model:

Database Columns

  • You can define the columns that will be stored in the database table for your model. This includes specifying the column name, data type, and any constraints like null: false.

Validations

  • You can define validations to ensure data integrity, such as presence, uniqueness, format, length, and numericality validations. For example:
ruby Copy
validates :name, presence: true, length: { minimum: 3 }

Associations

  • You can define relationships between models, such as has_many, belongs_to, has_one, and has_and_belongs_to_many associations. This allows you to easily access related data.

Callbacks

  • You can define callback methods that will be called at certain lifecycle events, such as before/after creation, update, save, or deletion. This allows you to add custom logic.

Scopes

  • You can define named scopes to encapsulate common queries, making your code more readable and reusable. For example:
ruby Copy
scope :active, -...
middle

middle

Gợi ý câu hỏi phỏng vấn

expert

What is a Rails engine?

middle

Mention what is the difference between calling super() and super call ?

junior

Explain how you define Instance Variable, Global Variable and Class Variable in Ruby?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào