Class: DynatableGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/dynatable_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_table_fileObject



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_viewObject



9
10
11
12
13
# File 'lib/generators/dynatable_generator.rb', line 9

def create_view
  app = ::Rails.application
  ext = app.config.generators.options[:rails][:template_engine] || :erb
  template "index.html.#{ext}", "app/views/#{plural_instance_name}/index.html.#{ext}"
end

#modelObject



28
29
30
# File 'lib/generators/dynatable_generator.rb', line 28

def model
  model_name.camelize.constantize
end

#model_instance_nameObject



32
33
34
# File 'lib/generators/dynatable_generator.rb', line 32

def model_instance_name
  model_name.underscore
end

#notify_controller_infoObject



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_nameObject



36
37
38
# File 'lib/generators/dynatable_generator.rb', line 36

def plural_instance_name
  model_instance_name.pluralize
end