Sha256: f71198ad77b47fd27e5649171952c4cf42535efaf8d193184f851dee95dc6078

Contents?: true

Size: 1.34 KB

Versions: 9

Compression:

Stored size: 1.34 KB

Contents

module Adauth
    module Generators
        # Generates the sessions controller
        class SessionsGenerator < ::Rails::Generators::Base
            source_root File.expand_path('../templates', __FILE__)
            argument :model_name, :type => :string, :default => "user"
            
            # 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
            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
        end
    end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
adauth-2.0.5 lib/generators/adauth/sessions/sessions_generator.rb
adauth-2.0.4 lib/generators/adauth/sessions/sessions_generator.rb
adauth-2.0.3 lib/generators/adauth/sessions/sessions_generator.rb
adauth-2.0.2 lib/generators/adauth/sessions/sessions_generator.rb
adauth-2.0.1 lib/generators/adauth/sessions/sessions_generator.rb
adauth-2.0.0 lib/generators/adauth/sessions/sessions_generator.rb
adauth-2.0.0pre2 lib/generators/adauth/sessions/sessions_generator.rb
adauth-2.0.0pre1 lib/generators/adauth/sessions/sessions_generator.rb
adauth-2.0.0pre lib/generators/adauth/sessions/sessions_generator.rb