Ruby on Rails 简介
-
Upload
sam-qiu -
Category
Technology
-
view
844 -
download
1
description
Transcript of Ruby on Rails 简介
Ruby on Rails 简介
邱锦森
Ruby on Rails 是什么
由 David Heninemeier Hansson 从 basecamp 中分离出来的MVC 框架。
由 Ruby 写成。
谁是 DHH ?
37signals 合伙人, Rework, Getting Real, Agile Web Development with Rails 作者之一。
为什么要用 Rails ,有什么好处?
约定优于配置
插件
强大的路由
ORM, Migrate
快速应付大部分应用场景
3 种运行模式development, test, production
" 模仿是最大的恭维 "
CakePHP(PHP)
Playframework(JAVA)
Grails(Groovy)
Rails 的设计原则
“ 不要重复自己”( Don't Repeat Yourself )“ 约定优于配置”( Convention Over Configuration )
例如: rest 请求 CURD 的 action 名
具体的 ruby 类型到 mysql 类型如何映射,字段长度
什么时候适用?
资料库形式,特别,不同于传统 CMS 的应用
性能要求不高要求开发效率高
运行于 *nix, Only POSIX
一个新的应用
$rails new smart -J -d mysql$cd smart $bundle install$rake db:migrate$rails server
http://localhost:3000/
手脚架 scaffold
$rails g scaffold post title:string content:text$rake db:migrate
生成 Model, View, Controller, Route
手脚架多余吗?
不多余,因为“约定优于配置”,所以你也会那样写:)
添加一个作者字段
生成 Post 时忘了添加某些字段?
$rails g migration AddAuthorToPost author:string$rake db:migrate
Routeresources :posts
Controllerclass PostsController < ApplicationController def show@post = Post.find(params[:id]) respond_to do |format|format.html format.xml { render :xml => @post } end end
View<h1><%= raw(@post.title) %><h1>
输入验证?
Model
class User < ActiveRecord::Base validates :username, :length => { :within => 1..20, : message => ' 用户名长度必需为 1-20' }, :uniqueness => true end
一些资源网站 Github -> Google Code Heroku -> Google App Engine
各种 Ruby cRuby Ruby Enterprise Edition 1 jRuby -> JAVA IronRuby
插件 HAML -> HTML Rspec (BDD) -> Unit Test (TDD) Devise ( 用户验证 )
感谢聆听:)