직전에 작성했던 commit 메시지 수정 직전에 작성했던 커밋 메시지를 수정하고 싶을 때는 git commit --amend 명령어를 사용 $ git commit --ammend 해당 명령어를 실행하면 에이터가 실행되고 방금 입력했던 commit 메시지가 나옵니다. 이를 수정하고 저장, 종료를 해주시면 됩니다. (에디터에 따라 저장 종료 방법은 다릅니다.)(git 에디터를 설정하고 싶으면 git config --global core.editor "vim" 와 같이 설정해주시면 됩니다.) git log --graph 명령어로 확인해보면 정상적으로 commit 메시지가 변경되었음을 확인할 수 있습니다.
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...
Rails 에서 외부 폰트의 위치 경로와 사용 시 path 입력 방법을 알아보겠습니다. 환경 : Ruby 2.0.0-p598 Rails 4.1 위의 그림과 같이 app - assets 하위에 기존의 images, javascripts, stylesheets 와 동일한 위치에 fonts 디렉터리를 생성해줍니다. 그리고 config/application.rb 에 다음과 같은 내용을 삽입해 줍니다. config.assets.paths
