Class: Sibyl::ModelGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- Sibyl::ModelGenerator
- Defined in:
- lib/generators/sibyl/model/model_generator.rb
Instance Method Summary collapse
Instance Method Details
#inject_into_model ⇒ Object
8 9 10 11 12 13 |
# File 'lib/generators/sibyl/model/model_generator.rb', line 8 def inject_into_model file = Rails.root.join("app", "models", "#{task.classify.underscore}.rb") inject_into_file file, after: "class #{task.classify} < ApplicationRecord" do "\n include Sibyl::Task\n" end end |
#modify_controller ⇒ Object
15 16 17 18 |
# File 'lib/generators/sibyl/model/model_generator.rb', line 15 def modify_controller file = Rails.root.join("app", "controllers", "#{task}_controller.rb") gsub_file file, /def show *(\r?\n)\s*end/, "def show\n respond_to do |format|\n format.html\n format.zip { send_file @#{task.classify.underscore}.zip_path }\n end\n end" end |
#modify_view ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/generators/sibyl/model/model_generator.rb', line 20 def modify_view file = Rails.root.join("app", "views", task, "index.html.erb") gsub_file file, "<th colspan=\"3\"></th>", "<th colspan=\"4\"></th>" inject_into_file file, after: "<td><%= link_to 'Show', #{task.classify.underscore} %></td>" do "\n <td><%= link_to 'Download', #{task.classify.underscore}_path(#{task.classify.underscore})+'.zip' %></td>" end end |