Rails 新人起步走

31
Rails 新人起步走

Transcript of Rails 新人起步走

⽇日期

Rails 新人起步走

Agenda

✤ 環境安裝!

✤ Rails 指令介紹!

✤ Scaffold

01

環境安裝homebrew!

Git!

rvm!

ruby gem!

! . rails!

Ruby

✤ Ruby is … !

✤ Ruby的作者--松本⾏行弘!

✤ http://www.ruby-lang.org/zh_tw/!

✤ 最新版本: 2.1.0!

✤ 使⽤用 IRB 練習!

✤ Mac 及 Linux -> 在 terminal 直接輸入 irb

homebrew

✤ 套件管理⼯工具!

✤ http://brew.sh/!

✤ install ⽅方式!

✤ sudo ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)”!

✤ brew !

✤ P.S 必須有xcode套件

Git

✤ 分散式的版本控制系統!

✤ http://git-scm.com/!

✤ install ⽅方式!

✤ brew install git

RVM(ruby version manager)

✤ RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems. !

✤ http://rvm.io/!

✤ https://rvm.io/rvm/install!

✤ install ⽅方式!

✤ \curl -sSL https://get.rvm.io | bash -s stable —ruby!

✤ 設定版本!

✤ rvm use ruby-2.0.0 --default

Ruby Gem

✤ RubyGems 是 Ruby 的 Package 管理系統,讓你輕易安裝及管理各種 Ruby programs/libraries。︒!

✤ gem -v RubyGems 的版本!

✤ gem update --system 升級你的RubyGems版本!

✤ gem install gemname 安裝某個套件!

✤ gem list 列出安裝的套件!

✤ gem list -r keyword 列出 RubyGems.org 上有此關鍵字的套件(可⽤用regular expression)

install Rails

!

!

✤ gem install rails --no-ri —no-rdoc

Rails 指令

✤ rails new project !

✤ rails console (rails c)!

✤ rails server (rails s)!

✤ rails generate (rails g)

Hello World

✤ step1 : rails new helloworld

Hello World

✤ step2 : bundle install

Hello World

✤ step3 :rails generate controller pages

Hello World

✤ step4 : 建⽴立 welcome action

Hello World

✤ Step5: 建⽴立 welcome page

Hello World

✤ Step6: 設定 route.rb (root page)

Hello World

✤ Step7: 啟動 Server!

✤ rails server

Hello World

Rails Project 目錄介紹

01

Scaffold介紹

create CRUD

✤ step 1 : rails g scaffold post title:string content:text

create CRUD

✤ 產⽣生 POST 的 models!

✤ title:string !

✤ content:text

create CRUD

✤ step 2 : rake db:migrate

create CRUD

✤ step 3 : rails server!

✤ step 4: http://localhost:3000/posts

01

Pow & Powder

Pow v.s Powder

Pow 是 37 Signals 開發出來的⼀一個很棒的東西,讓你檢視⾃自⼰己的開發進度時不需要⽤用 http://localhost:3000 這種需要 port number 的網址,可以⽤用 http://blog.dev 這樣的網址。︒

⽽而 Pow 也是⼀一個 Webserver , 好處如下:

1. 可以使⽤用 http://groupmy.dev 這種網址掛起網站,⽽而非使⽤用 rails s 跑在 port 3000。︒

2. 修改時,可以在不終⽌止 server 的情況下,去 reload server

powder

⽽而 powder 是⼀一個讓 pow 可以更容易使⽤用的⼯工具,我們將透過 powder 來安裝 pow。︒

The End

相關資源

✤ http://ihower.tw/rails2/!

✤ http://ihower.tw/git/!

✤ https://www.codeschool.com/courses/git-real!

✤ http://www.ruby-lang.org/zh_tw/documentation/!

✤ http://ruby.railstutorial.org/chapters/a-demo-app!

✤ http://hechien.logdown.com/posts/2013/10/08/working-with-rails-02

相關書籍

✤ Rails 101!

✤ Agile Web Development with Rails