Class: ShoppingCart::ControllerGenerator

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

Instance Method Summary collapse

Instance Method Details

#create_routesObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/shopping_cart/controller_generator.rb', line 25

def create_routes
  html = ''
  steps.each do |step|
    html +=
        "\nget '/checkout/#{step}', to: '#{name.underscore}##{step}'
         \npost '/checkout/add_#{step}', to: '#{name.underscore}#add_#{step}'"
  end
  inject_into_file 'config/routes.rb', before: "root" do
    "\nnamespace 'shopping_cart' do
    #{html}
     \nend\n"
  end
end

#create_steps_controllerObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/generators/shopping_cart/controller_generator.rb', line 6

def create_steps_controller
  html = ''
  steps.each do |step|
    html +=
      "\tdef #{step}\n\tend\n\tdef add_#{step}\n\tend\n\t"
  end

  create_file "app/controllers/shopping_cart/#{name.underscore}_controller.rb",
"module ShoppingCart
  class #{name}Controller < CheckoutController
layout 'shopping_cart/checkout'

#{html}
  end
end"
end

#create_viewsObject



41
42
43
44
45
# File 'lib/generators/shopping_cart/controller_generator.rb', line 41

def create_views
  steps.each do |step|
    create_file "app/views/shopping_cart/#{name.underscore}/#{step}.html.haml"
  end
end