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:
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:
scope :active, -...
middle

middle

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

junior

What do you mean by the term Scaffolding and what sort of advantages the Ruby can offer when it comes to same?

middle

What is the use of Destructive Method?

senior

Explain the difference between Page, Action, Fragment, Low-Level, SQL caching types

Bình luận

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

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