Class: ScaffoldPlus::Generators::FriendlyIdGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- ScaffoldPlus::Generators::FriendlyIdGenerator
- Defined in:
- lib/generators/scaffold_plus/friendly_id/friendly_id_generator.rb
Instance Method Summary collapse
Instance Method Details
#add_migration ⇒ Object
21 22 23 24 |
# File 'lib/generators/scaffold_plus/friendly_id/friendly_id_generator.rb', line 21 def add_migration return unless .migration? migration_template "friendly_id_migration.rb", "db/migrate/#{migration_name}.rb" end |
#update_controller ⇒ Object
40 41 42 43 44 |
# File 'lib/generators/scaffold_plus/friendly_id/friendly_id_generator.rb', line 40 def update_controller return if .finders? file = "app/controllers/#{table_name}_controller.rb" gsub_file file, /(#{class_name})\.find/, "\\1.friendly.find" end |
#update_model ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/generators/scaffold_plus/friendly_id/friendly_id_generator.rb', line 26 def update_model inject_into_class "app/models/#{name}.rb", class_name do text = .before? ? "\n" : "" text << " extend FriendlyId\n" if .finders? text << " friendly_id :#{attribute}, use: [:slugged, :finders]\n" else text << " friendly_id :#{attribute}, use: :slugged\n" end text << "\n" if .after? text end end |