-
Notifications
You must be signed in to change notification settings - Fork 2
Custom file placements (multiple)
Petr Marek edited this page Jan 14, 2019
·
1 revision
Let's create maps placements for MyProject::City.
Use folio_image_placement for Folio::Image placements and folio_document_placement for Folio::Document placements.
# app/models/my_project/file_placement/map.rb
class MyProject::FilePlacement::Map < Folio::FilePlacement::Base
folio_image_placement :map_placements
end# app/models/my_project/city.rb
class MyProject::City < ApplicationRecord
include Folio::HasAttachments
has_many_placements(:maps,
placements_key: :map_placements,
placement: 'MyProject::FilePlacement::Map')
endhas_many_placements creates two relations - has_many :map_placements and has_many :maps, through: :map_placements
# app/decorators/controllers/folio/console/base_controller_decorator.rb
Folio::Console::BaseController.class_eval do
private
def additional_file_placements_strong_params_keys
%i[
map_placements_attributes
]
end
end# config/locales/activerecord.cs.yml
---
cs:
activerecord:
attributes:
my_project/city:
map_placement: MapyUse the react_images/react_documents helper.
/ app/views/folio/console/my_project/cities/_form.slim
= tabs [:content, :maps]
= f.error_notification
.tab-content
= tab :content
= f.input :title
= tab :maps
= react_images(f.object.map_placements, attachmentable: 'my_project_city', \
type: :map_placements)