This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# アプリのトップページ(localhost:3000にアクセスした時に処理される先)を指定 | |
root 'controller#action' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# localhost:3000/urlにアクセスされた時の処理を定義 | |
get 'url' => 'controller#action' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 基本形 | |
get 'url' => 'controller#action' | |
# HTTPメソッドを変えたパターン | |
post 'url' => 'controller#create' | |
put 'url' => 'controller#update' | |
delete 'url' => 'controller#destroy' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RESTfulなURLを一括生成 | |
resources :url | |
# 一行書くだけで基本的なCRUD操作用の | |
# url#index, url#create, url#new, url#edit, url#show, url#update, url#destroy | |
# を生成することができる |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# index以外のRESTfulなURLを一括生成 | |
resource :url | |
# 一行書くだけでindex以外の | |
# url#create, url#new, url#edit, url#show, url#update, url#destroy | |
# を生成することができる |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# URLヘルパーに任意の文字を使用する場合 | |
get 'url' => 'controller#action', as: 'myurl' | |
# URLは localhost:3000/url | |
# URLヘルパーは myurl_pathとなる |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# URLに任意の文字列を使用する | |
get 'url' => 'controller#action', path: 'myurl' | |
# URLは localhost:3000/myurl | |
# URLヘルパーは url_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# resourcesで任意のURLのみ作成する | |
resources :url, only: [:index, :show] | |
# url#indexとurl#showのみ生成される | |
# もちろんresoureceでも可能 | |
resource :url, only: [:show, :new] | |
# url#show, url#newのみ生成される |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# resourcesで任意のURL以外を作成する | |
resources :url, except: [:index, :show] | |
# url#indexとurl#show以外のURLが生成される | |
# もちろんresoureceでも可能 | |
resource :url, except: [:show, :new] | |
# url#show, url#new以外のURLが生成される |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# コントローラにnamespaceを付与する | |
resources :url, module: :namespace | |
# 生成されるcontroller#actionが | |
# namespace/url#index, namespace/url#new, namespace/url#create・・・ | |
# となる | |
# app/controller/namespace/url_controller.rbみたいな感じでディレクトリ分けて管理したい時に | |
# ちなみに | |
get 'url' => 'controller#action', module: :namespace |
OlderNewer