기본적인 문법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 < Applicat..
기본 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..
어떠한 Action을 취한 후 이전 URL로 돌아가는 경우는 흔히 있다.예를들어 해당 게시글을 수정 혹은 삭제 후 다시 원래 URL로 돌아가는 것이 당연하다.이를 구현하기 위해서는 해당 Controller 에서 이전 URL을 저장하고 Action이 끝난 후 저장해둔 URL로 redirection 시켜주면 된다.예를들어 해당 report 삭제 후 다시 url 로 돌아가는 것을 구현하고자 하면 destory action에 이전 url을..
Rails 4 에서 Paperclip 과 Image Magick 으로 파일 업로드 및 이미지 처리를 할 수 있습니다.Paperclip 을 이용한 프로필 사진 기능을 만들어보도록 하겠습니다.Requirements1. Ruby 버전 1.9.2 이상2. Rails 버전 3.0 이상3. ImageMagick 설치1. ImageMagick 설치$ sudo apt-get install imagemagick$ sudo apt-get instal libmagick..
Ubuntu 에서 Ruby & Rails 설치하기 1. RVM 설치$ curl -sSL https://get.rvm.io | bash -s stable 2. RVM 실행$ rvm get stable 3. Ruby 설치에 필요한 패키지들 설치$ rvm requirements ("Command not found" 에러시)$ source ~/.rvm/scripts/rvm 4. 패키지 management 설치$ apt-get install lib..