Class: DynatableGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- DynatableGenerator
- Defined in:
- lib/generators/dynatable_generator.rb
Instance Method Summary collapse
- #create_table_file ⇒ Object
- #create_view ⇒ Object
- #model ⇒ Object
- #model_instance_name ⇒ Object
- #notify_controller_info ⇒ Object
- #plural_instance_name ⇒ Object
Instance Method Details
#create_table_file ⇒ Object
5 6 7 |
# File 'lib/generators/dynatable_generator.rb', line 5 def create_table_file template 'table.rb', "app/tables/#{plural_instance_name}_table.rb" end |
#create_view ⇒ Object
9 10 11 12 13 |
# File 'lib/generators/dynatable_generator.rb', line 9 def create_view app = ::Rails.application ext = app.config.generators.[:rails][:template_engine] || :erb template "index.html.#{ext}", "app/views/#{plural_instance_name}/index.html.#{ext}" end |
#model ⇒ Object
28 29 30 |
# File 'lib/generators/dynatable_generator.rb', line 28 def model model_name.camelize.constantize end |
#model_instance_name ⇒ Object
32 33 34 |
# File 'lib/generators/dynatable_generator.rb', line 32 def model_instance_name model_name.underscore end |
#notify_controller_info ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/generators/dynatable_generator.rb', line 15 def notify_controller_info puts <<-EOS \nChange your index route in app/controllers/#{plural_instance_name}_controller.rb to the following: def index respond_to do |format| format.html format.json { render json: #{model.name.pluralize}Table.new(view_context).to_builder.target! } end end EOS end |
#plural_instance_name ⇒ Object
36 37 38 |
# File 'lib/generators/dynatable_generator.rb', line 36 def plural_instance_name model_instance_name.pluralize end |