Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ruby on Rails Intro
Search
Sheng-Je Lin
April 17, 2014
Programming
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ruby on Rails Intro
Sheng-Je Lin
April 17, 2014
More Decks by Sheng-Je Lin
See All by Sheng-Je Lin
Build full-stack installer for Ruby Application with Omnibus.
v1nc3ntlaw
0
680
diff puppet chef
v1nc3ntlaw
2
190
T 客邦技術架構分享
v1nc3ntlaw
9
1.1k
T 客邦網站上線實務分享
v1nc3ntlaw
3
250
Other Decks in Programming
See All in Programming
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
110
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
160
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
230
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
680
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.4k
AutonomyとControlのあいだ:Graflowで記述するAIエージェント協調
myui
0
120
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
330
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.4k
New "Type" system on PicoRuby
pocke
1
830
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
2k
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
220
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
3.6k
Featured
See All Featured
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
1.1k
The Limits of Empathy - UXLibs8
cassininazir
1
350
Product Roadmaps are Hard
iamctodd
PRO
55
12k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
190
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.6k
Marketing to machines
jonoalderson
1
5.4k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
280
Transcript
Ruby on Rails 網站開發框架 @萬能科技大學 2014/04/17
about.me/v1nc3ntlaw 林聖哲 / Vincent /
[email protected]
2010/05 開始接觸使用 Ruby on
Rails (RoR)
為何選擇 RoR
Ruby on Rails 動態直譯式程式語言 Script Language 發明者:松本行弘 Yukihiro “Matz” Matsumoto
於 1995 年公開發表 自然、簡潔,讓程式設計師能夠快樂的寫程式
Ruby on Rails puts “Hello, world!”
Ruby on Rails 網站開發框架 發明者:David Heinemeier Hanson (DHH) 於 2004
年釋出開源 高生產力、快速開發
Ruby on Rails 高生產力 用更少的程式碼完成更多的事。 快速開發 預設好各種設定和遵循一定的規範。
為何選擇 RoR 快樂的寫程式又有很高的生產力 ( 快樂的賺錢 )
RoR 開發框架集成 建立遵循規範的專案資料夾結構 內建輔助開發網站時需要的工具 自動化需要重複操作的開發流程
RoR 基本目錄結構
應用模式遵循規範 MVC & RESTful
MVC Pattern Model-View-Controller
Model 網站使用到的物件資料和定義操作資料的邏輯, 一個 Model 會對應到一個資料庫的資料表。 class Post < ActiveRecord::Base def
like post.like_count += 1 post.save end end
ORM - ActiveRecord 負責與資料庫 (MySQL、PostgreSQL) 溝通 SQL 語法 SELECT title
FROM posts WHERE ID = 1; ActiveRecord Post.find_by_id(1).title
Controller 介於 Model 和 View 之間,處理瀏覽器的請求, 找出或處理 Model 物件資料,然後將資料傳到 View
顯示出來。 class PostsController < ApplicationController def show @post = Post.find(params[:id]) end end
View 可內嵌 Ruby 程式語法的 HTML 檔案, 輸出資料及網站頁面的呈現。 <html> ... <h1><%=
@post.title %></h1> <p><%= @post.content %></p> ... </html>
應用 MVC 使專案容易維護 保持程式 DRY (Don’t Repeat Yourself) 避免重複的程式碼 不同用途的程式碼放在各自的資料夾裡
分割資料呈現和商業邏輯的程式碼
RESTful
RESTful RESTful 架構的基礎概念為 REST 理論, 其兩個主要定理為: 1. 使用 Resource 當做識別的資源,使用
URLs 來代表 Resources 2. 同一個 Resource 可以有不同的 Representations 格式變化
RESTful 7 Actions 行為 | http verb | 網址 列表
| GET | /posts 新增 | GET | /posts/new 建立 | POST | /posts 秀出 | GET | /posts/:id 編輯 | GET | /posts/:id/edit 更新 | PUT | /posts/:id 刪除 | DELETE | /posts/:id
RESTful 7 Actions 行為 | controller | view 列表 |
posts#index | index.html.erb 新增 | posts#new | new.html.erb 建立 | posts#create | 秀出 | posts#show | show.html.erb 編輯 | posts#edit | edit.html.erb 更新 | posts#update | 刪除 | posts#destroy |
Assets Management JavaScript、CSS Style Sheets
使用更有生產力的轉譯語言 JavaScript => CoffeeScript CSS Style Sheets => SASS/SCSS
Assets Pipeline 將原本多個 .js 或 .css 檔案進行壓縮, 減少對伺服器的 HTTP Request
請求
內建指令工具
Rails Command Line rails new 建立新專案 rails generate 產生各程式碼檔案以及基本程式碼 rails
server 啓動本機伺服器檢視開發中的網站 rails console 進入互動式指令介面操作網站物件
自動產生程式碼
鷹架 Scaffold rails generate scaffold \ Post title:string content:text 產生
Post Model-View-Controller 的程式檔案和 操作資料庫修改的程式碼,以及 RESTful 的 Routes 設定
活躍的開源社群
RubyGems Ruby 社群套件管理系統 Don’t Reinvent the Wheel 不要重複造輪子 全球散佈各地的優秀工程師維護的高品質程式碼
RubyGems devise 賦予網站使用者註冊、登入和登出的機制 carrierwave 處理檔案上傳
為何選擇 RoR 快速完成你的 Idea 和想法, 實踐商業邏輯在市場中可不可行。
線上學習資源
Learn Ruby The Hard Way http://lrthw.github.io/ 《 笨方法學 Ruby 》習題
0 ~ 52 由淺入深
Try Ruby http://tryruby.org/
Ruby Warrior https://www.bloc.io/ruby-warrior/
Ruby on Rails 實戰聖經 http://ihower.tw/rails3/index.html
社群活動
Rails Girls Taipei 給想了解技術並實現想法的女性學習 Ruby on Rails 的社群。
Ruby Tuesday 不定期舉辦,邀請業界強者或大大技術分享
Rails Tuesday 技術交流、問題請教、閒聊、Social 工作經驗
RubyConf Taiwan 年度 Ruby 程式語言大會,邀請國內外講者
Q & A