Class: Panel::ResourceGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/panel/resource_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_routeObject



6
7
8
9
10
# File 'lib/generators/panel/resource_generator.rb', line 6

def add_route
  insert_into_file 'config/routes.rb', after: /namespace :panel(.*)/ do |match|
    "#{match}\n    resources :#{table_name}"
  end
end

#add_scopeObject



12
13
14
15
16
# File 'lib/generators/panel/resource_generator.rb', line 12

def add_scope
  insert_into_file "app/models/#{singular_name}.rb", after: /class #{singular_name.camelize}(.*)/ do
    "\n\n  scope :search, ->(term) { where('', term: \"%\#{term}%\") }"
  end
end

#add_templatesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/generators/panel/resource_generator.rb', line 18

def add_templates
  @param_singular = ":#{singular_name}"
  @param_plural = ":#{plural_name}"
  @instance_singular = "@#{singular_name}"
  @instance_plural = "@#{plural_name}"
  @index_path = "panel_#{index_helper}_path"
  @params_method = "#{singular_name}_params"
  template 'resource/resource_controller.rb', "app/controllers/panel/#{table_name}_controller.rb"
  template 'resource/_form.html.erb', "app/views/panel/#{table_name}/_form.html.erb"
  template 'resource/new.html.erb', "app/views/panel/#{table_name}/new.html.erb"
  template 'resource/edit.html.erb', "app/views/panel/#{table_name}/edit.html.erb"
  template 'resource/index.html.erb', "app/views/panel/#{table_name}/index.html.erb"
end