9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/generators/trk_datatables/trk_datatables_generator.rb', line 9
def create
begin
class_name.constantize
@trk_class_name = "#{class_name.pluralize}Datatable"
@trk_file_name = "#{plural_name}_datatable"
rescue NameError => e
Rails.logger.info e.message
@skip_model = true
@trk_class_name = "#{class_name}Datatable"
@trk_file_name = "#{singular_name}_datatable"
end
template "trk_datatable.rb", "app/datatables/#{@trk_file_name}.rb"
say " ======================================================================\n You can use in your controller\n\n # app/controllers/\#{plural_name}_controller.rb\n class \#{class_name.pluralize}Controller < ApplicationController\n def index\n @datatable = \#{@trk_class_name}.new view_context\n end\n\n def search\n render json: \#{@trk_class_name}.new(view_context)\n end\n end\n\n In your views mkdir app/views/\#{plural_name}\n # app/views/\#{plural_name}/index.html.erb\n <h1>\#{class_name.pluralize}</h1>\n <%= @datatable.render_html search_\#{plural_name}_path(format: :json) %>\n\n And in routes\n\n # config/routes.rb\n Rails.application.routes.draw do\n resources :\#{plural_name} do\n collection do\n post :search\n end\n end\n end\n ======================================================================\n TEXT\nend\n"
|