Class: Adauth::Generators::SessionsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/adauth/sessions/sessions_generator.rb

Overview

Generates the sessions controller

Instance Method Summary collapse

Instance Method Details

#generate_sessionsObject

Generates the sessions controller

Called as:

rails g adauth:sessions

Has 1 optional input of “model_name”, which needs to be set the the model that include Adauth::UserModel



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/generators/adauth/sessions/sessions_generator.rb', line 14

def generate_sessions
    template "sessions_controller.rb.erb", "app/controllers/sessions_controller.rb"
    template "new.html.erb", "app/views/sessions/new.html.erb"
    route "resources :sessions"
    route "match \"/adauth\" => \"sessions#create\""
    route "match \"/signout\" => \"sessions#destroy\""
    puts "       extra  Add this code to your ApplicationController"
    puts ""
    puts "              helper_method :current_user"
    puts ""
    puts "              def current_user"
    puts "                  @current_user ||= User.find(session[:user_id]) if session[:user_id]"
    puts "              end"
end