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

后端 未结 7 1840
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条回答
  •  渐次进展
    2021-01-11 14:08

    Since you want this particular application to not generate routes.

    You can deploy your gems to local/project folder and override them.

    In your rails project folder

    bundle install --path /my_rails_path/lib/
    

    Now you can see all of you libraries ported to your project lib/ folder

    Go to the below file (path changes depending upon your versions)

    lib/ruby/1.9.1/gems/railties-3.2.15/lib/rails/generators/rails/controller/controller_generator.rb

    and comment the function add_routes

      def add_routes
        #actions.reverse.each do |action|
        #  route %{get "#{file_name}/#{action}"}
        #end
      end
    

    NOTE: This trick will not affect any other rails application in your system

提交回复
热议问题