Class: PixelforceCms::Generators::ControllerGenerator

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

Instance Method Summary collapse

Instance Method Details

#create_controllerObject



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

def create_controller
  @controller_name = controller_name
  template "base_controller.rb", "app/controllers/admin/base_controller.rb"
  template "admin_controller.rb", "app/controllers/admin/#{file_name.pluralize}_controller.rb"
end

#create_routeObject



23
24
25
26
27
28
29
# File 'lib/generators/pixelforce_cms/controller_generator.rb', line 23

def create_route
  sentinel = "authenticated :user do\n"
  routing_code = "resources :#{file_name.pluralize}, controller: 'admin/#{file_name.pluralize}'"
  in_root do
    inject_into_file 'config/routes.rb', "    #{routing_code}\n", { :after => sentinel, :verbose => false }
  end
end

#create_viewsObject



15
16
17
18
19
20
21
# File 'lib/generators/pixelforce_cms/controller_generator.rb', line 15

def create_views
  @controller_name = controller_name
  # template 'index.html.haml', "app/views/admin/#{file_name}/index.html.haml"
  template 'new.html.haml', "app/views/admin/#{file_name}/new.html.haml"
  template 'edit.html.haml', "app/views/admin/#{file_name}/edit.html.haml"
  template '_form.html.haml', "app/views/admin/#{file_name}/_form.html.haml"
end