Class: PhocoderRails::Generators::ScaffoldGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- PhocoderRails::Generators::ScaffoldGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/phocoder_rails/scaffold_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_controller_file ⇒ Object
- #create_helper_file ⇒ Object
- #create_migration_file ⇒ Object
- #create_model_file ⇒ Object
- #create_route ⇒ Object
- #create_views ⇒ Object
-
#do_a_thing ⇒ Object
class_option :view_engine, :type => :string, :aliases => “-t”, :desc => “Template engine for the views.
Class Method Details
.next_migration_number(dirname) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/generators/phocoder_rails/scaffold_generator.rb', line 15 def self.next_migration_number(dirname) if ActiveRecord::Base. Time.new.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end |
Instance Method Details
#create_controller_file ⇒ Object
37 38 39 |
# File 'lib/generators/phocoder_rails/scaffold_generator.rb', line 37 def create_controller_file template 'controller.rb', File.join('app/controllers', class_path, "#{file_name.pluralize}_controller.rb") end |
#create_helper_file ⇒ Object
33 34 35 |
# File 'lib/generators/phocoder_rails/scaffold_generator.rb', line 33 def create_helper_file template 'helper.rb', File.join('app/helpers', class_path, "#{file_name.pluralize}_helper.rb") end |
#create_migration_file ⇒ Object
23 24 25 26 |
# File 'lib/generators/phocoder_rails/scaffold_generator.rb', line 23 def create_migration_file migration_template 'model_migration.rb', "db/migrate/create_#{file_name.pluralize}.rb" #migration_template 'model_thumbnail_migration.rb', "db/migrate/create_#{file_name.singularize}_thumbnails.rb" end |
#create_model_file ⇒ Object
28 29 30 31 |
# File 'lib/generators/phocoder_rails/scaffold_generator.rb', line 28 def create_model_file template 'model.rb', File.join('app/models', class_path, "#{file_name.singularize}.rb") template 'model_thumbnail.rb', File.join('app/models', class_path, "#{file_name.singularize}_thumbnail.rb") end |
#create_route ⇒ Object
48 49 50 |
# File 'lib/generators/phocoder_rails/scaffold_generator.rb', line 48 def create_route route("resources :#{file_name.pluralize}, :except=>[:edit,:update]") end |
#create_views ⇒ Object
41 42 43 44 45 46 |
# File 'lib/generators/phocoder_rails/scaffold_generator.rb', line 41 def create_views directory 'views', File.join('app/views', class_path, "#{file_name.pluralize}" ) #["_form.html.erb","index.html.erb","new.html.erb","show.html.erb"].each do |view| # template "views/#{view}", File.join('app/views', class_path, "#{file_name.pluralize}", view ) #end end |
#do_a_thing ⇒ Object
class_option :view_engine, :type => :string, :aliases => “-t”, :desc => “Template engine for the views. Available options are ‘erb’ and ‘haml’.”, :default => “erb” class_option :haml, :type => :boolean, :default => false
55 56 57 |
# File 'lib/generators/phocoder_rails/scaffold_generator.rb', line 55 def do_a_thing puts "We are doing a thing!!!!!!!!!!!!!!!! #{file_name}" end |