15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/generators/beautiful_storage_generator.rb', line 15
def install_storage
gem("image_processing", '~> 1.2')
Bundler.with_unbundled_env do
run "bundle install"
end
run "bin/rails active_storage:install"
raise "Model must be specified" if model.blank?
raise "Attachment must be specified" if storage_name.blank?
inject_into_file("app/models/#{engine_name}#{model}.rb",
"\n
has_one_attached :#{storage_name}
\n", after: "< ApplicationRecord")
inject_into_file("app/models/#{engine_name}#{model}.rb", ":#{storage_name},", :after => "def self.permitted_attributes\n return ")
inject_into_file("app/views/#{engine_name}#{model_pluralize}/_form.html.erb",
" <div class='form-group'>
<%= f.label :#{storage_name}, t('app.models.#{model}.bs_attributes.#{storage_name}', :default => '#{storage_name}').capitalize, :class => 'control-label' %><br />
<%= f.file_field :#{storage_name}, direct_upload: true, :class => 'form-control' %>
</div>\n", before: '<!-- Beautiful_scaffold - AddField - Do not remove -->')
inject_into_file("app/views/#{engine_name}#{model_pluralize}/_form.html.erb",
", multipart: true", after: "form_for(@#{model}")
inject_into_file("app/views/#{engine_name}#{model_pluralize}/show.html.erb",
"<p><b><%= t('app.models.#{model}.bs_attributes.#{storage_name}', :default => '#{storage_name}') %>:</b><br><%= image_tag @#{model}.#{storage_name}.variant(resize_to_limit: [100, 100]) %></p>",
before: "<!-- Beautiful_scaffold - AddField - Field - Do not remove -->")
say "You must run 'rake db:migrate' to create activestorage migrations !"
end
|