aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_dispatch/journey/router.rb3
-rw-r--r--railties/lib/rails/generators/rails/controller/controller_generator.rb8
-rw-r--r--railties/test/generators/controller_generator_test.rb7
3 files changed, 15 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/journey/router.rb b/actionpack/lib/action_dispatch/journey/router.rb
index fe3fc0a9fa..21817b374c 100644
--- a/actionpack/lib/action_dispatch/journey/router.rb
+++ b/actionpack/lib/action_dispatch/journey/router.rb
@@ -105,7 +105,8 @@ module ActionDispatch
routes.concat get_routes_as_head(routes)
end
- routes.sort_by!(&:precedence).select! { |r| r.matches?(req) }
+ routes.select! { |r| r.matches?(req) }
+ routes.sort_by!(&:precedence)
routes.map! { |r|
match_data = r.path.match(req.path_info)
diff --git a/railties/lib/rails/generators/rails/controller/controller_generator.rb b/railties/lib/rails/generators/rails/controller/controller_generator.rb
index 7588a558e7..fbecab1823 100644
--- a/railties/lib/rails/generators/rails/controller/controller_generator.rb
+++ b/railties/lib/rails/generators/rails/controller/controller_generator.rb
@@ -2,6 +2,8 @@ module Rails
module Generators
class ControllerGenerator < NamedBase # :nodoc:
argument :actions, type: :array, default: [], banner: "action action"
+ class_option :skip_routes, type: :boolean, desc: "Dont' add routes to config/routes.rb."
+
check_class_collision suffix: "Controller"
def create_controller_files
@@ -9,8 +11,10 @@ module Rails
end
def add_routes
- actions.reverse.each do |action|
- route generate_routing_code(action)
+ unless options[:skip_routes]
+ actions.reverse.each do |action|
+ route generate_routing_code(action)
+ end
end
end
diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb
index 4b2f8539d0..c906d56b8f 100644
--- a/railties/test/generators/controller_generator_test.rb
+++ b/railties/test/generators/controller_generator_test.rb
@@ -70,6 +70,13 @@ class ControllerGeneratorTest < Rails::Generators::TestCase
assert_file "config/routes.rb", /get 'account\/foo'/, /get 'account\/bar'/
end
+ def test_skip_routes
+ run_generator ["account", "foo", "--skip-routes"]
+ assert_file "config/routes.rb" do |routes|
+ assert_no_match /get 'account\/foo'/, routes
+ end
+ end
+
def test_invokes_default_template_engine_even_with_no_action
run_generator ["account"]
assert_file "app/views/account"