routes.rb 에서 nested 라우팅 관리를 하다보면 아래와 같은 경우가 종종 생긴다. resources :messaged doresources :commentsresources :categoriesresources :tagsend resources :posts doresources :commentsresources :categoriesresources :tagsend resources :items doresources :commentsresources :categoriesresources :tagsend comments, categories, tags 와 같은 똑같은 resources 가 중복되어 사용되는 경우 concern method를 이용하여 간단히 나타낼 수 있다. concern :soci..
app/views/users/index.html.erb app/views/users/_user.html.erb app/controllers/users_controller.rbclass UsersController < ApplicationControllerdef create@user = User.new(params[:user])end def destroy@user = User.find(params[:id])@user.destroyendend app/views/create.js.erb$('div#users').append("");... app/views/users/destroy.js.erb$('#').fadeOut();
N+1 Query Problem예를 들어 Client 모델에 관계되어 있는 address 모델에서의 postcode를 뽑을 때 아래와 같은 코드를 사용하면,clients = Client.limit(10)clients.each do |client|puts client.address.postcodeend겉으로는 괜찮아 보이나 11번의 SQL 쿼리를 실행하는 안타까운 점이있다.Client Load (0.1ms) SELECT * FROM "clients" LIMIT 10 Address Load (0.2ms) SELECT * FROM "address" WHERE "client_id" = 1Address Load (0.2ms) SELECT * FROM "address" WHERE "client_id" = 2...A..
기본적인 문법 class PostsController < ApplicationControllerdef edit@post = Post.find(params[:id])if session[:user_id] != @post.user_idflash[:notice] = "Sorry, you can't edit this post"redirect_to post_pathendendend 대체가능한 문법class PostsController < ApplicationControllerdef edit@post = Post.find(params[:id])if session[:user_id] != @post.user_idredirect_to (post_path, notice: "Sorry, you can't edit this p..
기본 Create 문법 t = User.newt.name = "Jinny"t.phone = "01012341234"t.save 대체가능 Create 문법1t. = User.new(name: "Jinny"phone: "01012341234") t.save 대체가능 Create 문법2t = User.create(name: "Jinny", phone: "01012341234") 기본 Update 문법 t = User.find(3)t.name = "Jinny"t.phone = "01012341234"t.save 대체가능 Update 문법1t = User.find(3)t.attributes = {name: "Jinny"phone: "01012341234"} t.save 대체가능 Update 문법2t = User...
- Total
- Today
- Yesterday
- Message Queue
- 한미반도체
- 삼성전자
- 반도체관련주
- ruby on rails
- codecademy
- HBM
- 투자전략
- 이수페타시스
- Rails
- SK하이닉스
- rabbitmq
- 주식투자
- IT
- 웹프로그래밍
- javascript
- 티스토리 초대장
- Java
- ubuntu
- install
- 이펙티브 자바
- 자료구조
- CSS
- OpenStack
- ruby
- 프로그래밍
- html
- 현대차
- 알고리즘
- 엔비디아
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
