Skip to content

Commit

Permalink
Replicate behaviour from rails-api to not create edit/new routes on a…
Browse files Browse the repository at this point in the history
…pi apps by default, to mimic behaviour from controllers.

See also rails-api/rails-api@41f949f

Fixes rails#24573
  • Loading branch information
vipulnsward committed Apr 20, 2016
1 parent 697384d commit 8671dbd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
@@ -1,6 +1,10 @@
module Rails
module Generators
class ResourceRouteGenerator < NamedBase # :nodoc:

class_option :api, type: :boolean,
desc: "Preconfigure smaller stack for API only apps"

# Properly nests namespaces passed into a generator
#
# $ rails generate resource admin/users/products
Expand All @@ -21,7 +25,9 @@ def add_resource_route
end

# inserts the primary resource
write("resources :#{file_name.pluralize}", route_length + 1)
resource_string = "resources :#{file_name.pluralize}"
resource_string << ", except: [:new, :edit]" if options.api?
write(resource_string, route_length + 1)

# ends blocks
regular_class_path.each_index do |index|
Expand Down
2 changes: 1 addition & 1 deletion railties/test/generators/namespaced_generators_test.rb
Expand Up @@ -409,7 +409,7 @@ def test_api_scaffold_with_namespace_on_invoke

# Route
assert_file "config/routes.rb" do |route|
assert_match(/^ namespace :admin do\n resources :roles\n end$/, route)
assert_match(/^ namespace :admin do\n resources :roles, except: \[:new, :edit\]\n end$/, route)
end

# Controller
Expand Down
2 changes: 1 addition & 1 deletion railties/test/generators/scaffold_generator_test.rb
Expand Up @@ -99,7 +99,7 @@ def test_api_scaffold_on_invoke

# Route
assert_file "config/routes.rb" do |route|
assert_match(/resources :product_lines$/, route)
assert_match(/resources :product_lines, except: \[:new, :edit\]$/, route)
end

# Controller
Expand Down

0 comments on commit 8671dbd

Please sign in to comment.