Routing
![]()
![]()
$ cat config/routes.rb Rails.application.routes.draw do # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html namespace :admin do root "top#index" end namespace :user do root "top#index" end namespace :member do root "top#index" end end $ bin/rails g controller admin/top Running via Spring preloader in process 9524 create app/controllers/admin/top_controller.rb invoke erb create app/views/admin/top invoke rspec $ bin/rails g controller user/top Running via Spring preloader in process 9559 create app/controllers/user/top_controller.rb invoke erb create app/views/user/top invoke rspec $ bin/rails g controller member/top Running via Spring preloader in process 9600 create app/controllers/member/top_controller.rb invoke erb create app/views/member/top invoke rspec $ cat app/controllers/member/top_controller.rb class Member::TopController < ApplicationController def index render action: "index" end end $ cat app/controllers/user/top_controller.rb class User::TopController < ApplicationController def index render action: "index" end end $ cat app/controllers/admin/top_controller.rb class Admin::TopController < ApplicationController def index render action: "index" end end $ cat app/views/member/top/index.html.erb <% @title = "Member" %> <h1><%= @title %></h1> $ cat app/views/user/top/index.html.erb <% @title = "User" %> <h1><%= @title %></h1> $ cat app/views/admin/top/index.html.erb <% @title = "Admin" %> <h1><%= @title %></h1>
$ cat config/routes.rb
Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
namespace :admin do
root "top#index"
end
namespace :user do
root "top#index"
end
namespace :member do
root "top#index"
end
end
$ bin/rails g controller admin/top
Running via Spring preloader in process 9524
create app/controllers/admin/top_controller.rb
invoke erb
create app/views/admin/top
invoke rspec
$ bin/rails g controller user/top
Running via Spring preloader in process 9559
create app/controllers/user/top_controller.rb
invoke erb
create app/views/user/top
invoke rspec
$ bin/rails g controller member/top
Running via Spring preloader in process 9600
create app/controllers/member/top_controller.rb
invoke erb
create app/views/member/top
invoke rspec
$ cat app/controllers/member/top_controller.rb
class Member::TopController < ApplicationController
def index
render action: "index"
end
end
$ cat app/controllers/user/top_controller.rb
class User::TopController < ApplicationController
def index
render action: "index"
end
end
$ cat app/controllers/admin/top_controller.rb
class Admin::TopController < ApplicationController
def index
render action: "index"
end
end
$ cat app/views/member/top/index.html.erb
<% @title = "Member" %>
<h1><%= @title %></h1>
$ cat app/views/user/top/index.html.erb
<% @title = "User" %>
<h1><%= @title %></h1>
$ cat app/views/admin/top/index.html.erb
<% @title = "Admin" %>
<h1><%= @title %></h1>