Ruby on Rails

ActiveStorage

File uploads, attachments, has_one_attached, has_many_attached, S3, variants, previews

20 câu hỏi phỏng vấn·
Mid-Level
1

Which command should be used to install ActiveStorage in a Rails application?

Câu trả lời

The rails active_storage:install command generates the necessary migrations to create the active_storage_blobs and active_storage_attachments tables. These tables store metadata about uploaded files. After installation, run rails db:migrate to apply the migrations to the database.

2

Which macro should be used to attach a single file (avatar) to a User model?

Câu trả lời

The has_one_attached macro allows attaching a single file to a model. It automatically creates the methods avatar, avatar=, avatar.attach, avatar.attached? and avatar.purge. For multiple files, use has_many_attached instead.

3

Which macro should be used to attach multiple files (documents) to a Project model?

Câu trả lời

The has_many_attached macro allows attaching multiple files to a model. It creates the methods documents, documents.attach, documents.attached? and documents.purge. Files are stored in a collection and can be added or removed individually.

4

Which method should be used to check if a file is already attached to a record?

5

In which configuration file should the default storage service (local, S3, etc.) be defined?

+17 câu hỏi phỏng vấn

Nắm vững Ruby on Rails cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí