Class: RnStack::MediaGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- RnStack::MediaGenerator
- Defined in:
- lib/generators/rn_stack/media/media_generator.rb
Instance Method Summary collapse
Instance Method Details
#add_has_one_attached ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/generators/rn_stack/media/media_generator.rb', line 8 def add_has_one_attached # Simple abstraction to add ActiveStorage association to a model path = "app/models/#{model_name.underscore}.rb" if File.exist?(path) inject_into_file path, " has_one_attached :#{field_name}\n", after: "class #{model_name.camelize} < ApplicationRecord\n" say "Added 'has_one_attached :#{field_name}' to #{path}" else say "Model file not found: #{path}", :red end end |