How to prevent Rails controller generator to modify config/routes.rb

后端 未结 7 1826
Happy的楠姐
Happy的楠姐 2021-01-11 13:27

Sometimes I run a command like rails g controller foo index to generate skeletons for controller and template.

Because I don\'t want to have helpers and

7条回答
  •  -上瘾入骨i
    2021-01-11 13:55

    Looks like routes generation is hardcoded. Have a look at this method https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/controller/controller_generator.rb#L12

    I think, the simplest way is to override with monkey-patch . Something like

    module Rails
      module Generators
        class ControllerGenerator < NamedBase 
          def add_routes
            #do nothing...
          end
        end
      end
    end
    

    you can put it to initializer and try.

提交回复
热议问题