Class: Starter::ResourceGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Extended by:
ActiveRecord::Generators::Migration
Includes:
Rails::Generators::Migration, Rails::Generators::ResourceHelpers
Defined in:
lib/generators/starter/resource/resource_generator.rb

Instance Method Summary collapse

Methods included from ActiveRecord::Generators::Migration

next_migration_number

Instance Method Details

#copy_view_filesObject

def create_root_view_folder

empty_directory File.join("app/views", controller_file_path)

end



33
34
35
36
37
38
# File 'lib/generators/starter/resource/resource_generator.rb', line 33

def copy_view_files
  available_views.each do |view|
    filename = view_filename_with_extensions(view)
    template filename, File.join("app/views", controller_file_path, File.basename(filename))
  end
end

#generate_controllerObject



17
18
19
# File 'lib/generators/starter/resource/resource_generator.rb', line 17

def generate_controller
  template 'controller.rb', "app/controllers/#{plural_name.underscore}_controller.rb"
end

#generate_migrationObject



25
26
27
# File 'lib/generators/starter/resource/resource_generator.rb', line 25

def generate_migration
  migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
end

#generate_modelObject



21
22
23
# File 'lib/generators/starter/resource/resource_generator.rb', line 21

def generate_model
  template 'model.rb', "app/models/#{singular_name.underscore}.rb"
end

#generate_routesObject



41
42
43
44
45
46
47
# File 'lib/generators/starter/resource/resource_generator.rb', line 41

def generate_routes
  if named_routes?
    route golden_7_named, "Named RESTful routes"
  else
    route golden_7, "RESTful routes"
  end
end