Class: Layout::Generators::DeviseGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_devise_viewsObject



11
12
13
14
15
16
17
18
19
# File 'lib/generators/layout/devise/devise_generator.rb', line 11

def add_devise_views
  copy_file 'sessions/new.html.erb', 'app/views/devise/sessions/new.html.erb'
  copy_file 'passwords/new.html.erb', 'app/views/devise/passwords/new.html.erb'
  copy_file 'passwords/edit.html.erb', 'app/views/devise/passwords/edit.html.erb'
  unless File.exists?('app/views/devise/registrations/new.html.erb')
    copy_file 'registrations/new.html.erb', 'app/views/devise/registrations/new.html.erb'
  end
  copy_file 'registrations/edit.html.erb', 'app/views/devise/registrations/edit.html.erb'
end

#add_name_fieldObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/generators/layout/devise/devise_generator.rb', line 21

def add_name_field
  if Object.const_defined?('User')
    if User.column_names.include? 'name'
      gsub_file 'app/views/devise/registrations/new.html.erb', /:autofocus => true, /, ''
      gsub_file 'app/views/devise/registrations/edit.html.erb', /:autofocus => true, /, ''
      inject_into_file 'app/views/devise/registrations/new.html.erb', name_field, :before => "      <%= f.label :email %>"
      inject_into_file 'app/views/devise/registrations/edit.html.erb', name_field, :before => "      <%= f.label :email %>"
    end
  end
end