
ActiveStorage
File uploads, attachments, has_one_attached, has_many_attached, S3, variants, previews
1Which command should be used to install ActiveStorage in a Rails application?
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.
2Which macro should be used to attach a single file (avatar) to a User model?
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.
3Which macro should be used to attach multiple files (documents) to a Project model?
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.
Which method should be used to check if a file is already attached to a record?
In which configuration file should the default storage service (local, S3, etc.) be defined?
+17 면접 질문