Class: Pages::Generators::UsersGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/pages/users/users_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_devise_name_fieldObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/generators/pages/users/users_generator.rb', line 34

def add_devise_name_field
  return unless File.exists?('config/initializers/devise.rb')
  if Object.const_defined?('User')
    if User.column_names.include? 'name'
      permits_file = File.expand_path("../templates", __FILE__) + '/devise/devise_permitted_parameters.rb'
      devise_permitted = "\n" + File.read(permits_file)
      inject_into_file 'app/controllers/application_controller.rb', devise_permitted, :after => "protect_from_forgery with: :exception"
      prepend_file 'app/views/users/_user.html.erb', "<td><%= link_to user.name, user %></td>\n"
      inject_into_file 'app/views/users/show.html.erb', "\n<p>Name: <%= @user.name if @user.name %></p>", :before => "\n<p>Email"
    end
  end
end

#create_devise_pagesObject



18
19
20
21
22
23
# File 'lib/generators/pages/users/users_generator.rb', line 18

def create_devise_pages
  return unless File.exists?('config/initializers/devise.rb')
  copy_file 'devise/users_controller.rb', 'app/controllers/users_controller.rb'
  route = '  resources :users'
  inject_into_file 'config/routes.rb', route + "\n", :after => "devise_for :users\n"
end

#create_omniauth_pagesObject



25
26
27
28
29
30
31
32
# File 'lib/generators/pages/users/users_generator.rb', line 25

def create_omniauth_pages
  return unless File.exists?('config/initializers/omniauth.rb')
  copy_file 'omniauth/users_controller.rb', 'app/controllers/users_controller.rb'
  copy_file 'omniauth/_user.html.erb', 'app/views/users/_user.html.erb'
  copy_file 'omniauth/show.html.erb', 'app/views/users/show.html.erb'
  route = '  resources :users'
  inject_into_file 'config/routes.rb', route + "\n", :after => "routes.draw do\n"
end

#create_pagesObject



10
11
12
13
14
15
16
# File 'lib/generators/pages/users/users_generator.rb', line 10

def create_pages
  copy_file 'users/_user.html.erb', 'app/views/users/_user.html.erb'
  copy_file 'users/index.html.erb', 'app/views/users/index.html.erb'
  copy_file 'users/show.html.erb', 'app/views/users/show.html.erb'
  generate 'pages:home -f'
  copy_file 'visitors/index.html.erb', 'app/views/visitors/index.html.erb'
end