Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 assets for every controller, I put following codes into config/application.rb:

config.generators do |g|
  g.helper false
  g.assets false
end

There is another thing I don't want to happen. The generator adds a line get "foo/index" to my config/routes.rb. How can I prevent it?

like image 588
Tsutomu Avatar asked Jan 01 '14 09:01

Tsutomu


2 Answers

As of Rails 4.2, it's possible to disable route generation with the following code in your application.rb:

config.generators do |g|
  g.skip_routes  true
end

Source: https://github.com/rails/rails/commit/4b173b8ed90cb409c1cdfb922914b41b5e212cb6

like image 52
sevenseacat Avatar answered Oct 15 '22 20:10

sevenseacat


This is counter intuitive, but here it is what you're looking for:

config.generators do |g|
  g.skip_routes true
end
like image 40
felipehespanhol Avatar answered Oct 15 '22 19:10

felipehespanhol