Ruby on Rails

ActiveStorage

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

20 면접 질문·
Mid-Level
1

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

답변

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?

답변

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?

답변

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 면접 질문

다음 면접을 위해 Ruby on Rails을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기