Class: Rails::Generators::ControllerScaffoldingGenerator
- Inherits:
-
NamedBase
- Object
- NamedBase
- Rails::Generators::ControllerScaffoldingGenerator
- Defined in:
- lib/generators/controller/controller_scaffolding_generator.rb
Instance Method Summary collapse
- #add_routes ⇒ Object
-
#check_for_model ⇒ Object
TODO: only do if behavior = :invoke maybe?.
- #create_controller_file ⇒ Object
- #run_sns_gen ⇒ Object
- #setup_actions ⇒ Object
Instance Method Details
#add_routes ⇒ Object
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_model ⇒ Object
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_file ⇒ Object
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_gen ⇒ Object
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 .search_sort? end |
#setup_actions ⇒ Object
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 |