Class: FlexibleAdmin::DeviseGenerator

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

Instance Method Summary collapse

Instance Method Details

#deviseObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/generators/flexible_admin/devise_generator.rb', line 23

def devise
  append_file "Gemfile", "\n", :force => true
  gem 'devise'
  
  inside Rails.root do
    run "bundle install"
  end        
  
  unless File.exists?(Rails.root.join("config/initializers/devise.rb"))
    say "Installing devise"
    generate "devise:install"
  end
  
  unless File.exists?(Rails.root.join("app/models/admin_user.rb"))
    generate "devise AdminUser"
    template "user_sign_in.html.erb", "app/views/admin/admin_users/sessions/new.html.erb"
    gsub_file 'config/routes.rb', "devise_for :admin_users", "devise_for :admin_users, :path_prefix => 'admin', :controllers => {:sessions => 'admin/admin_users/sessions' }"
    template "admin_user_sessions_controller.rb", "app/controllers/admin/admin_users/sessions_controller.rb"
  end
  
  say "you now need to run 'rake db:migrate' to create the admin_users table", :blue
  say "after that make your first admin_user in the console: AdminUser.create!(email: '[email protected]', password: 'password')", :blue
end

#require_authenticationObject



13
14
15
16
17
18
19
20
21
# File 'lib/generators/flexible_admin/devise_generator.rb', line 13

def require_authentication
  if File.exists?(Rails.root.join("app/controllers/admin_controller.rb"))
    auth_code = "before_filter :authenticate_admin_user!"
    sentinel = "class AdminController < ApplicationController"
    in_root do
      inject_into_file 'app/controllers/admin_controller.rb', "\n    #{auth_code}", { :after => sentinel, :verbose => true }
    end
  end
end