Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahastudio/481bb135639ab824d1dc to your computer and use it in GitHub Desktop.
Save ahastudio/481bb135639ab824d1dc to your computer and use it in GitHub Desktop.

SQLite3 설치

https://www.sqlite.org/

$ brew install sqlite3

Ruby on Rails 설치

https://github.com/rails/rails

$ gem update --system
$ gem install bundler --no-document
$ gem install rails -v 5.0.0.beta1 --no-document

Ruby on Rails 프로젝트 만들기

먼저 “작업 공간”으로 이동합니다. 여기서는 그냥 $HOME/workspace라고 가정하겠습니다.

$ cd ~/workspace
$ rails new api-demo
$ cd api-demo

Git 사용하기

Git 저장소 만들기

$ git init

Commit

$ git add .
$ git commit

Pow 서버 사용하기

https://github.com/basecamp/pow

$ curl get.pow.cx | sh

https://github.com/Rodreegez/powder

$ gem install powder --no-document
$ powder link
$ powder open

Web Site URL: http://api-demo.dev/

CRUD 찍어내기

$ bin/rails generate scaffold post title:string body:text
$ bin/rake db:migrate RAILS_ENV=test
$ bin/rake test
$ bin/rake db:migrate

Resource URL: http://api-demo.dev/posts

Validation

$ vi app/models/post.rb
class Post < ApplicationRecord
  validates :title, presence: true
  validates :body, presence: true
end

Console 사용하기

$ bin/rails console

> Post.all
> Post.first
> Post.last
> post = _
> post.title
> post.title = '조...조은 글이다'
> post.save!
> post.title = ''
> post.save!
> exit

Commit!

잊지 마세요!

@ahastudio
Copy link
Author

2019년 6월 26일 기준으로 바뀐 점:

  1. Ruby on Rails의 버전이 크게 올라갔습니다. 버전을 명시하지 말고 그냥 gem install rails --no-document라고 설치하세요.

  2. Pow 서버는 .test 도메인을 기본으로 쓰도록 바뀌었습니다.
    지금은 .dev 도메인이 진짜 따로 생겨서 충돌이 일어날 수 있으니 Pow 서버 사용에 주의하세요. https://get.dev/

  3. 더이상 bin/rake 블라블라 형태를 쓰지 않습니다. bin/rails 블라블라bundle exec rails 블라블라 형태로 실행하세요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment