Skip to content

Chapter 2 config/routes.rb listing 4-6 changes #15

@notapatch

Description

@notapatch

One of the confusing things in Chapter 2 is the block inside the namespace :api

Listing 4. config/routes.rb

Rails.application.routes.draw do
  namespace :api, defaults: { format: :json } do
    namespace :v1 do                   <= This guy
      # We are going to list our resources here
    end
  end
end

You then commit as "Set the routes constraints for the api". So far no problem. Then we see.

Listing 5. config/routes.rb

Rails.application.routes.draw do
  # Api definition
  namespace :api, defaults: { format: :json }  do
    # We are going to list our resources here           <= where's it gone?
  end
end

This is a bit confusing as the version namespace :v1 has disappeared. Maybe it's because it wasn't interesting? Maybe because it's a mistake? However, In Listing 6 we have namespace changed to scope.

Listing 6. config/routes.rb

Rails.application.routes.draw do
  # Api definition
  namespace :api, defaults: { format: :json }  do
    scope module: :v1 do            <= so we changed namespace to scope?
      # We are going to list our resources here
    end
  end
end

Is the progression from Listing 4 (adding an inner namespace), Listing 5 (missing it out again) and Listing 6 (inner scope module) deliberate? It's quite confusing to follow and not clear from the text why these changes happened.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions