Class: Registration::RegistrationGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_routesObject



20
21
22
23
24
25
# File 'lib/generators/registration/registration_generator.rb', line 20

def add_routes
  route "root \"/\""
  route "resource :registration, only: [:new, :create]"
  route "get \"sign_in\", to: \"sessions#new\", as: :sign_in"
  route "delete \"sign_out\", to: \"sessions#destroy\", as: :sign_out"
end

#create_controllerObject



16
17
18
# File 'lib/generators/registration/registration_generator.rb', line 16

def create_controller
  template "registrations_controller.rb", "app/controllers/registrations_controller.rb"
end

#create_helperObject



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
# File 'lib/generators/registration/registration_generator.rb', line 27

def create_helper
  create_file "app/helpers/authentication_helper.rb", "    module AuthenticationHelper\n      def link_to_sign_in_or_out(show_user: false)\n        if authenticated?\n          button_to \"Sign Out\", sign_out_path, method: :delete\n        else\n          link_to \"Sign In\", sign_in_path\n        end\n      end\n\n      def show_username_if_signed_in\n        if authenticated?\n          content = \"Signed in as \\\#{Current.user.email_address}\"\n          content.html_safe\n        end\n      end\n    end\n  RUBY\n\n  # Inject include statement at the correct place\n  inject_into_class \"app/controllers/application_controller.rb\", \"ApplicationController\", <<~RUBY\n    include AuthenticationHelper\n  RUBY\nend\n"

#create_sign_inObject



12
13
14
# File 'lib/generators/registration/registration_generator.rb', line 12

def 
  template "sign_in_form.html.erb", "app/views/sessions/new.html.erb", force: true
end

#create_viewObject



8
9
10
# File 'lib/generators/registration/registration_generator.rb', line 8

def create_view
  template "registration_form.html.erb", "app/views/registrations/new.html.erb"
end