일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- mac
- 쿠버네티스
- MySQL
- 우분투
- ruby #string #strip #split #gsub
- change_column_null
- 오랜지파이
- Visual Studio Code
- Ruby on Rails
- docket
- 사용중인포트검색
- docker
- install
- 도커
- Migrate
- Rails
- after_save
- after_update
- Time.znoe.now
- 이것이 자바다
- 설치
- change_column
- 주차장 시스템
- Orange Pi 3B
- 우분투 24
- ubuntu
- Kotlin
- with_indifferent_access
- Java
- RUBY
- Today
- Total
중고 신입이 개발해보기..
Rails Routes 본문
Ruby On Rails에서 라우트 하는것을 ..
- 브라우저에서 Routes를 확인할때
http://localhost:3000/rails/info/routes
- 콘솔에선
$ rake routes
컨트롤러를 만들면
$ ./bin/rails g controller Infobox index
routes.rb 파일에
get 'infobox/index'
라고 자동으로 만들어진다.. 컨트롤러 이름뒤에 index를 추가해놓아서 그런거임
resources :kinghts
Helper | HTTP Verb | Path | Controller#Action |
---|---|---|---|
Path / Url | |||
knights_path | GET | /knights(.:format) |
knights#index |
POST | /knights(.:format) |
knights#create |
|
new_knight_path | GET | /knights/new(.:format) |
knights#new |
edit_knight_path | GET | /knights/:id/edit(.:format) |
knights#edit |
knight_path | GET | /knights/:id(.:format) |
knights#show |
PATCH | /knights/:id(.:format) |
knights#update |
|
PUT | /knights/:id(.:format) |
knights#update |
|
DELETE | /knights/:id(.:format) |
knights#destroy |
rosource :prince
Helper | HTTP Verb | Path | Controller#Action |
---|---|---|---|
Path / Url | |||
new_prince_path | GET | /prince/new(.:format) |
princes#new |
edit_prince_path | GET | /prince/edit(.:format) |
princes#edit |
prince_path | GET | /prince(.:format) |
princes#show |
PATCH | /prince(.:format) |
princes#update |
|
PUT | /prince(.:format) |
princes#update |
|
DELETE | /prince(.:format) |
princes#destroy |
|
POST | /prince(.:format) |
princes#create |
매개 변수 제약 조건 옵션
ㄴ constraints
form 매개 변수 제거
ㄴ format:false
resource :prince, format: false
Helper | HTTP Verb | Path | Controller#Action |
---|---|---|---|
Path / Url | |||
new_prince_path | GET | /prince/new |
princes#new |
edit_prince_path | GET | /prince/edit |
princes#edit |
prince_path | GET | /prince |
princes#show |
PATCH | /prince |
princes#update |
|
PUT | /prince |
princes#update |
|
DELETE | /prince |
princes#destroy |
|
POST | /prince |
princes#create |
컨트롤 클래스와 URL헬퍼의 이름 수정
resource :prince, format: false, as: :king_sun
Helper | HTTP Verb | Path | Controller#Action |
---|---|---|---|
Path / Url | |||
new_king_sun_path | GET | /prince/new |
princes#new |
edit_king_sun_path | GET | /prince/edit |
princes#edit |
king_sun_path | GET | /prince |
princes#show |
PATCH | /prince |
princes#update |
|
PUT | /prince |
princes#update |
|
DELETE | /prince |
princes#destroy |
|
POST | /prince |
princes#create |
resource :prince, format: false, controller: :queen_sun
Helper | HTTP Verb | Path | Controller#Action |
---|---|---|---|
Path / Url | |||
new_prince_path | GET | /prince/new |
queen_sun#new |
edit_prince_path | GET | /prince/edit |
queen_sun#edit |
prince_path | GET | /prince |
queen_sun#show |
PATCH | /prince |
queen_sun#update |
|
PUT | /prince |
queen_sun#update |
|
DELETE | /prince |
queen_sun#destroy |
|
POST | /prince |
queen_sun#create |
resource :prince, format: false, as: :king_sun, controller: :queen_sun
Helper | HTTP Verb | Path | Controller#Action |
---|---|---|---|
Path / Url | |||
new_king_sun_path | GET | /prince/new |
queen_sun#new |
edit_king_sun_path | GET | /prince/edit |
queen_sun#edit |
king_sun_path | GET | /prince |
queen_sun#show |
PATCH | /prince |
queen_sun#update |
|
PUT | /prince |
queen_sun#update |
|
DELETE | /prince |
queen_sun#destroy |
|
POST | /prince |
queen_sun#create |
./bin/rails g controller WebEx::Textings
ㄴ 위와 같이 컨트롤러를 생성하면
$ ./bin/rails g controller WebEx::Textings |
Running via Spring preloader in process 81947 create app/controllers/web_ex/textings_controller.rb invoke erb create app/views/web_ex/textings invoke test_unit create test/controllers/web_ex/textings_controller_test.rb invoke helper create app/helpers/web_ex/textings_helper.rb invoke test_unit invoke assets invoke coffee create app/assets/javascripts/web_ex/textings.coffee invoke scss create app/assets/stylesheets/web_ex/textings.scss |
namespace :WebEx
|
아래와같이 routes.rb에 생성된다.
namespace :admin do resources :kings end |
Helper | HTTP Verb | Path | Controller#Action |
---|---|---|---|
Path / Url | |||
admin_kings_path | GET | /admin/kings(.:format) |
admin/kings#index |
POST | /admin/kings(.:format) |
admin/kings#create |
|
new_admin_king_path | GET | /admin/kings/new(.:format) |
admin/kings#new |
edit_admin_king_path | GET | /admin/kings/:id/edit(.:format) |
admin/kings#edit |
admin_king_path | GET | /admin/kings/:id(.:format) |
admin/kings#show |
PATCH | /admin/kings/:id(.:format) |
admin/kings#update |
|
PUT | /admin/kings/:id(.:format) |
admin/kings#update |
|
DELETE | /admin/kings/:id(.:format) |
admin/kings#destro |
url 패턴과 url 헬퍼가 영향을 준다.
scope module: :admin do resources :kings end |
Helper | HTTP Verb | Path | Controller#Action |
---|---|---|---|
Path / Url | |||
kings_path | GET | /kings(.:format) |
admin/kings#index |
POST | /kings(.:format) |
admin/kings#create |
|
new_king_path | GET | /kings/new(.:format) |
admin/kings#new |
edit_king_path | GET | /kings/:id/edit(.:format) |
admin/kings#edit |
king_path | GET | /kings/:id(.:format) |
admin/kings#show |
PATCH | /kings/:id(.:format) |
admin/kings#update |
|
PUT | /kings/:id(.:format) |
admin/kings#update |
|
DELETE | /kings/:id(.:format) |
admin/kings#destroy |
scope :admin do resources :kings end |
Helper | HTTP Verb | Path | Controller#Action |
---|---|---|---|
Path / Url | |||
kings_path | GET | /admin/kings(.:format) |
kings#index |
POST | /admin/kings(.:format) |
kings#create |
|
new_king_path | GET | /admin/kings/new(.:format) |
kings#new |
edit_king_path | GET | /admin/kings/:id/edit(.:format) |
kings#edit |
king_path | GET | /admin/kings/:id(.:format) |
kings#show |
PATCH | /admin/kings/:id(.:format) |
kings#update |
|
PUT | /admin/kings/:id(.:format) |
kings#update |
|
DELETE | /admin/kings/:id(.:format) |
kings#destroy |
...
'Back-End > Ruby On Rails' 카테고리의 다른 글
Rails 영상] 기본 블로그만들기 (0) | 2018.11.29 |
---|---|
rails 토큰 만들기. (0) | 2018.11.23 |
Rails Routes 설명 (0) | 2018.10.17 |
Rails 유용한 Gem (0) | 2018.09.06 |
Rails 5.2 Active Storage and beyond (0) | 2018.07.12 |