logo资料库

Ruby on Rails 4 Tutorial 中文版.pdf

第1页 / 共460页
第2页 / 共460页
第3页 / 共460页
第4页 / 共460页
第5页 / 共460页
第6页 / 共460页
第7页 / 共460页
第8页 / 共460页
资料共460页,剩余部分请下载后查看
目录
作者译者
致中国读者
第 1 章 从零到部署
1.1 简介
1.1.1 给不同读者群的建议
1.1.2 Rails 的性能
1.1.3 本书排版约定
1.2 搭建环境
1.2.1 开发环境
1.2.2 安装 Ruby,RubyGems,Rails 和 Git
1.2.3 第一个程序
1.2.4 Bundler
1.2.5 rails server
1.2.6 模型-视图-控制器(MVC)
1.3 用 git 做版本控制
1.3.1 安装与设置
1.3.2 添加文件并提交
1.3.3 git 为我们带来了什么好处?
1.3.4 GitHub
1.3.5 分支,编辑,提交,合并
1.4 部署
1.4.1 搭建 Heroku 部署环境
1.4.2 Heroku 部署第一步
1.4.3 Heroku 部署第二步
1.4.4 Heroku 的其他命令
1.5 小结
第 2 章 演示程序
2.1 规划程序
2.1.1 用户模型
2.1.2 微博模型
2.2 Users 资源(users resource)
2.2.1 浏览用户相关的页面
2.2.2 MVC 实践
2.2.3 上述 Users 资源的缺陷
2.3 Microposts 资源
2.3.1 概览 Microposts 资源
2.3.2 限制微博内容的长度
2.3.3 一个用户有多篇微博
2.3.4 继承关系
2.3.5 部署演示程序
2.4 小结
第 3 章 基本静态的页面
3.1 静态页面
3.2 第一个测试
3.2.1 测试驱动开发
3.2.2 添加页面
3.3 有点动态内容的页面
3.3.1 测试标题的变化
3.3.2 让标题测试通过
3.3.3 嵌入式 Ruby
3.3.4 使用布局文件来消除重复
3.4 小结
3.5 练习
3.6 高级技术
3.6.1 去掉 bundle exec
3.6.2 使用 Guard 自动测试
3.6.3 使用 Spork 加速测试
3.6.4 在 Sublime Text 中进行测试
第 4 章 Rails 背后的 Ruby
4.1 导言
4.2 字符串和方法
4.2.1 注释
4.2.2 字符串
4.2.3 对象及向其传递消息
4.2.4 定义方法
4.2.5 回顾一下标题的帮助方法
4.3 其他的数据类型
4.3.1 数组和 Range
4.3.2 块
4.3.3 Hash 和 Symbol
4.3.4 重温引入 CSS 的代码
4.4 Ruby 类
4.4.1 构造器
4.4.2 类的继承
4.4.3 修改内置的类
4.4.4 控制器类
4.4.5 用户类
4.5 小结
4.6 练习
第 5 章 完善布局
5.1 添加一些结构
5.1.1 网站导航
5.1.2 Bootstrap 和自定义的 CSS
5.1.3 局部视图
5.2 Sass 和 asset pipeline
5.2.1 Asset pipeline
5.2.2 句法强大的样式表
5.3 布局中的链接
5.3.1 路由测试
5.3.2 Rails 路由
5.3.3 具名路由
5.3.4 简化 RSpec 测试代码
5.4 用户注册:第一步
5.4.1 Users 控制器
5.4.2 “注册”页面的 URL 地址
5.5 小结
5.6 练习
第 6 章 用户模型
6.1 User 模型
6.1.1 数据库迁移
6.1.2 模型文件
6.1.3 创建用户对象
6.1.4 查找用户对象
6.1.5 更新用户对象
6.2 用户数据验证
6.2.1 用户模型测试
6.2.2 验证存在性
6.2.3 长度验证
6.2.4 格式验证
6.2.5 唯一性验证
6.3 加上安全密码
6.3.1 加密密码
6.3.2 密码和密码确认
6.3.3 用户身份验证
6.3.4 用户的安全密码
6.3.5 创建用户
6.4 小结
6.5 练习
第 7 章 用户注册
7.1 显示用户信息
7.1.1 调试信息和 Rails 环境
7.1.2 Users 资源
7.1.3 使用预构件测试用户资料页面
7.1.4 添加 Gravatar 头像和侧边栏
7.2 注册表单
7.2.1 测试用户注册功能
7.2.2 使用 form_for
7.2.3 表单的 HTML
7.3 注册失败
7.3.1 可正常使用的表单
7.3.2 健壮参数
7.3.3 注册时的错误提示信息
7.4 注册成功
7.4.1 完整的注册表单
7.4.2 Flash 消息
7.4.3 首次注册
7.4.4 部署到生产环境,并开启 SSL
7.5 小结
7.6 练习
第 8 章 登录和退出
8.1 session 和登录失败
8.1.1 Sessions 控制器
8.1.2 测试登录功能
8.1.3 登录表单
8.1.4 分析表单提交
8.1.5 显示 Flash 消息
8.2 登录成功
8.2.1 “记住我”
8.2.2 定义 sign_in 方法
8.2.3 获取当前用户
8.2.4 改变导航链接
8.2.5 注册后直接登录
8.2.6 退出
8.3 Cucumber 简介(选读)
8.3.1 安装和设置
8.3.2 功能和步骤定义
8.3.3 小技巧:自定义 RSpec 匹配器
8.4 小结
8.5 练习
第 9 章 更新、显示和删除用户
9.1 更新用户
9.1.1 编辑表单
9.1.2 编辑失败
9.1.3 编辑成功
9.2 权限限制
9.2.1 必须先登录
9.2.2 用户只能编辑自己的资料
9.2.3 更友好的转向
9.3 列出所有用户
9.3.1 用户列表
9.3.2 示例用户
9.3.3 分页
9.3.4 视图重构
9.4 删除用户
9.4.1 管理员
9.4.2 destroy 动作
9.5 小结
9.6 练习
第 10 章 用户的微博
10.1 Microposts 模型
10.1.1 基本模型
10.1.2 第一个数据验证
10.1.3 用户和微博之间的关联
10.1.4 改进 Micropost 模型
10.1.5 验证微博内容
10.2 显示微博
10.2.1 充实用户资料页面
10.2.2 示例微博
10.3 微博相关的操作
10.3.1 访问限制
10.3.2 创建微博
10.3.3 临时的动态列表
10.3.4 删除微博
10.4 小结
10.5 练习
第 11 章 关注用户
11.1 关系模型
11.1.1 数据模型带来的问题以及解决方式
11.1.2 User 和 Relationship 模型之间的关联
11.1.3 数据验证
11.1.4 被关注的用户
11.1.5 粉丝
11.2 关注用户功能的网页界面
11.2.1 用户关注用到的示例数据
11.2.2 数量统计和关注表单
11.2.3 关注列表和粉丝列表页面
11.2.4 关注按钮的常规实现方式
11.2.5 关注按钮的 Ajax 实现方式
11.3 动态列表
11.3.1 目的和策略
11.3.2 初步实现动态列表
11.3.3 子查询(subselect)
11.3.4 新的动态列表
11.4 小结
11.4.1 扩展示例程序的功能
11.4.2 后续学习的资源
11.5 练习
3 3 ............................................................................................................................................................ 2 2 ........................................................................................................................................................................ .....................................................................................................................................................................................iviv ..................................................................................................................................................................................... .................................................................................................................................................................................. .................................................................................................................................................................................. vv .................................................................................................................................................................................................. ..................................................................................................................................................................................................vivi 1 ...................................................................................................................................................................... 1 ...................................................................................................................................................................... 11 1.1 ........................................................................................................................................................................... 2 1.2 ................................................................................................................................................................... 6 1.3 git .................................................................................................................................................. 20 1.4 ......................................................................................................................................................................... 30 1.5 ......................................................................................................................................................................... 35 ........................................................................................................................................................................ 3737 2.1 ................................................................................................................................................................. 37 2.2 Users users resource................................................................................................................................ 40 2.3 Microposts ...................................................................................................................................................... 52 2.4 ......................................................................................................................................................................... 61 ............................................................................................................................................................ 6363 3.1 ................................................................................................................................................................. 66 3.2 ............................................................................................................................................................. 73 3.3 ............................................................................................................................................. 81 3.4 ......................................................................................................................................................................... 90 3.5 ......................................................................................................................................................................... 91 3.6 ................................................................................................................................................................. 93 ..................................................................................................................................................... 104104 4.1 ....................................................................................................................................................................... 104 4.2 ....................................................................................................................................................... 108 4.3 ................................................................................................................................................... 114 4.4 Ruby ................................................................................................................................................................. 124 4.5 ....................................................................................................................................................................... 132 4.6 ....................................................................................................................................................................... 132 ...................................................................................................................................................................... 134134 5.1 ....................................................................................................................................................... 135 5.2 Sass asset pipeline............................................................................................................................................ 150 5.3 ....................................................................................................................................................... 159 5.4 ............................................................................................................................................... 171 5.5 ....................................................................................................................................................................... 175 5.6 ....................................................................................................................................................................... 175 ...................................................................................................................................................................... 179179 6.1 User .............................................................................................................................................................. 180 6 6 ...................................................................................................................................................................... ii 4 Rails Ruby 4 Rails Ruby ..................................................................................................................................................... 5 5 ......................................................................................................................................................................
9 9 .............................................................................................................................................. 8 8 .................................................................................................................................................................. 7 7 ...................................................................................................................................................................... 6.2 ....................................................................................................................................................... 189 6.3 ....................................................................................................................................................... 203 6.4 ....................................................................................................................................................................... 214 6.5 ....................................................................................................................................................................... 214 ...................................................................................................................................................................... 216216 7.1 ....................................................................................................................................................... 216 7.2 ............................................................................................................................................................... 232 7.3 ............................................................................................................................................................... 244 7.4 ............................................................................................................................................................... 252 7.5 ....................................................................................................................................................................... 259 7.6 ....................................................................................................................................................................... 259 .................................................................................................................................................................. 262262 8.1 session .............................................................................................................................................. 262 8.2 ............................................................................................................................................................... 277 8.3 Cucumber ..................................................................................................................................... 295 8.4 ....................................................................................................................................................................... 302 8.5 ....................................................................................................................................................................... 303 .............................................................................................................................................. 305305 9.1 ............................................................................................................................................................... 305 9.2 ............................................................................................................................................................... 315 9.3 ....................................................................................................................................................... 326 9.4 ............................................................................................................................................................... 341 9.5 ....................................................................................................................................................................... 349 9.6 ....................................................................................................................................................................... 351 ................................................................................................................................................................ 355355 10.1 Microposts .................................................................................................................................................. 355 10.2 ............................................................................................................................................................. 368 10.3 ................................................................................................................................................. 377 10.4 ..................................................................................................................................................................... 399 10.5 ..................................................................................................................................................................... 399 .................................................................................................................................................................... 403403 11.1 ............................................................................................................................................................. 403 11.2 ................................................................................................................................. 419 11.3 ............................................................................................................................................................. 443 11.4 ..................................................................................................................................................................... 450 11.5 ..................................................................................................................................................................... 453 iii 10 10 ................................................................................................................................................................ 11 11 ....................................................................................................................................................................
Michael Hartl Ruby on Rails Web RailsSoace Rails Ruby on Rails Insoshi Ruby 2011 Ruby Hero Y Combinator Andor Chen WordPress Ruby Rails Web Rails iv
Ruby “”David Heinemeier Hansson Rails RubyRails Ruby on Rails Web Ruby on Rails Tutorial Rails Web Web Ruby on Rails Andor Chen Ruby on Rails Tutorial Ruby on Rails Tutorial Michael Hartl Ruby is a delightful computer language explicitly designed to make programmers happy. This philosophy influenced David Heinemeier Hansson to pick Ruby when implementing the Rails web framework. Ruby on Rails, as it’s often called, makes building custom web applications faster and easier than ever before. In the past few years, the Ruby on Rails Tutorial has become the leading introduction to web development with Rails. In our interconnected world, computer programming and web application development are rapidly rising in importance, and I am excited to support Ruby on Rails in China. Although it is important to learn English, which is the international language of programming, it’s often helpful at first to learn in your native language. It is for this reason that I am grateful to Andor Chen for producing the Chinese-language edition of the Ruby on Rails Tutorial book. I’ve never been to China, but I definitely plan to visit some day. I hope I’ll have the chance to meet some of you when I do! Best wishes and good luck, Michael Hartl Author The Ruby on Rails Tutorial v
CD Baby Ruby on Rails PHP Google Michael Hartl Ruby on Rails Tutorial Rails Rails “Rails ” Rails TDD GitGitHub Heroku Rails Derek Sivers (sivers.org) CD Baby vi
1 1 Ruby on Rails “ Ruby on Rails Web ” Rails Web Rails Rails 4 Web Ruby on Rails Rails 4 Rails 4 Rails 4 Rails 3.2 1.1 “” 7.3.2 Rails Turbolinks RSpec “” 1.1 “” Rails 3.2 Rails 3.2 • Rails 3.2 Rails 4.01.2.2 • Capybara DSL 3.10 • RSpec .should expect().to3.2.1 • have_selector('title', ...) have_title(...)3.3.1 • HTTP PUT PATCH 3.3 • JavaScript Turbolinks 3.26 • root to: 'path' root 'path' 5.24 • find_by_thing(...) find_by(thing: ...)6.1.4 • rake db:test:prepare rake test:prepare6.2.1 • attr_accessible“”7.3.2 • 8.2.1 • before_filter before_action 9.21 • Capybara match: :first 9.43 • default_scope Hash lambda 10.11 • dup to_a 10.12 • XPath 11.2.4 Rails Rails Web Ruby on Rails HTMLCSS 1
Rails Derek Sivers TDD Ruby on Rails 1.2 Rails first_app Git 1.3 1.4 2 Rails 1.1 demo_app 2 URI URL1 sample_app “”Test-driven Development, TDD 3 Rails Ruby 10 11 Rails 2 Web 1.1 2004 Rails Web Rails37signalsGithubShopifyScribdTwitterDisneyHulu Yellow Pages Web Rails ENTPthoughtbotPivotal Labs Hashrocket Rails Ruby on Rails MIT Rails Ruby Rails Web “”Domain-speific Language, DSL Web HTML URL Rails Rails Web Rails REST Web Rails DHH Rails Merb Rails Ruby Web Rails Merb API 1. URI Uniform Resources Identifier URL Uniform Resource LocatorURL 2. Twiiter 2
分享到:
收藏