Class: Rails::Generators::ControllerScaffoldingGenerator

Inherits:
NamedBase
  • Object
show all
Defined in:
lib/generators/controller/controller_scaffolding_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_routesObject



67
68
69
70
71
72
# File 'lib/generators/controller/controller_scaffolding_generator.rb', line 67

def add_routes
  #TODO Handle nested resources here (look at namespace_ladder in scaffold generators)
  #TODO: make this a little more intelligent so if an action specified to the
  # generator is Non-RESTful just add a simple "get" route for it
  route "resources :#{plural_table_name.to_sym}"
end

#check_for_modelObject

TODO: only do if behavior = :invoke maybe?



53
54
55
56
57
58
59
60
61
# File 'lib/generators/controller/controller_scaffolding_generator.rb', line 53

def check_for_model #TODO: only do if behavior = :invoke maybe?
  #this rescue has only been smoke-tested. can't find a way to unit test
  begin
  table_name.classify.constantize #throws runtime if model doesn't exist
  rescue NameError
    raise Thor::Error, 
      "Cannot run controller scaffold for model (#{table_name.classify}) that doesn't yet exist."
  end
end

#create_controller_fileObject



63
64
65
# File 'lib/generators/controller/controller_scaffolding_generator.rb', line 63

def create_controller_file
  template 'controller.rb', File.join('app/controllers', class_path, "#{file_name}_controller.rb")
end

#run_sns_genObject



75
76
77
78
# File 'lib/generators/controller/controller_scaffolding_generator.rb', line 75

def run_sns_gen
  #TODO: should see if we can do this with a hook_for as well
  invoke "sql_search_n_sort:install" if options.search_sort?  
end

#setup_actionsObject



49
50
51
# File 'lib/generators/controller/controller_scaffolding_generator.rb', line 49

def setup_actions
  @actions = actions.nil? || actions.empty? ? %w(index new create edit update destroy) : actions
end