0
0

More than 3 years have passed since last update.

【namespace】 admin(管理者)用、URL作成

Posted at

【ゴール】 

「namespace」を使用してURLをカスタマイズ

例: http://localhost:3000/admins/top  ←みたいな感じにしたい。

【開発環境】

■ Mac OS catalina
■ Ruby on Rails (5.2.4.2)
■ Virtual Box:6.1
■ Vagrant: 2.2.7

【実装】

まずは新規アプリケーションを作成

Mac内.terminal
 $ rails new (アプリケーション名)
       ↓
 $ cd (アプリケーション名)
       ↓
 $ rails s -b 0.0.0.0

アプリケーションが起動するかを確認

スクリーンショット 2020-04-18 23.36.46.png

次に config/routes.rbへ移動し、以下のコマンドを実装

config/routes.rb
Rails.application.routes.draw do
 namespace :admins do
   get 'top'=>'admins#top'
 end
end

mac terminalへ移動し、rails routesを入力!!

Mac内.terminal
 $ rails routes
     
       (省略)

 admins_top GET    /admins/top(.:format)    admins/top#top
#上記のルートが記述あればOK!

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0