Skip to content

Commit 98cd944

Browse files
author
Joel Quenneville
committed
added a variable to the to the generator
1 parent dfd4c5c commit 98cd944

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
class AjaxdatatableGenerator < Rails::Generators::Base
22
source_root File.expand_path('../templates', __FILE__)
3+
argument :model, type: :string
34

45
def generate_ajaxdatatable
5-
template 'datatable.rb', File.join('app/datatables', "datatable.rb")
6+
template 'datatable.rb', File.join('app/datatables', "#{model}.rb")
67
end
78
end

lib/generators/ajaxdatatable/templates/datatable.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
class <%#= class_name %>Datatable < AjaxDatatableRails
2-
model_name <%#= class_name %>
1+
class <%= model.classify %>Datatable < AjaxDatatableRails
2+
model_name <%= model.classify %>
33
columns # insert array of column names here
44
searchable_columns #insert array of columns that will be searched
55

@@ -9,8 +9,8 @@ def data
99
# generate a 2-dimensional array that holds the data
1010
end
1111

12-
def <%#= class_name.downcase %>
13-
@records ||= fetch_records
12+
def <%= model.tableize %>
13+
@<%= model.tableize %> ||= fetch_records
1414
end
1515

1616
def get_raw_records

0 commit comments

Comments
 (0)