第四章 Rails背后的Ruby
2013-12-04 18:19
363 查看
4.1 导言
定义full_title帮助方法$ vim app/helpers/application_helper.rb
module ApplicationHelper def full_title(page_title) base_title = "Ruby on Rails Tutorial Sample App" if page_title.empty? base_title else "#{base_title} | #{page_title}" end end end
简化布局
$ vim app/views/layouts/application.html.erb
修改title
<title><%=full_title(:title)%></title>
更新现有的测试:
vim spec/requests/static_pages_spec.rb
require 'spec_helper' describe "Static pages" do describe "Home page" do it "should have the content 'Sample App'" do visit '/static_pages/home' expect(page).to have_content('Sample App') end it "should have the base title" do visit '/static_pages/home' expect(page).to have_title("Ruby on Rails Tutorial Sample App") end it "should not have a custom page title" do visit '/static_pages/home' expect(page).not_to have_title("| Home") end . . . end
运行测试,获得一个测试失败。
$ bundle exec rspec spec/requests/static_pages_spec.rb
为了让测试通过删除首页视图中的provide那行
4.2 字符串和方法
进入控制台$rails console
相关文章推荐
- Ruby on Rails Tutorial 第四章 Rails背后的Ruby 之 其他数据类型(二)
- Ruby on Rails Tutorial 第四章 Rails背后的Ruby 之 类
- Ruby on Rails Tutorial 第四章 Rails背后的Ruby 之 字符串
- [Ruby on Rails Tutorial]04-Rails 背后的 Ruby
- ruby on rails tutorial 笔记 (第四章)
- Ruby for Rails 最佳实践Ⅵ
- ueditor之ruby on rails 版
- Running Background Jobs in Ruby on Rails Revisited
- 用百度开源webuploader 上传图片 rubyonrails 后端代码
- rvm 管理多版本 ruby 和 rails
- Ruby on rails开发从头来(windows)(五)-对输入进行验证 (修正原版错误)
- [Ruby on Rails实战圣经]Ajax 应用程式
- Ruby 和 Rails 的国际化与本地化技术
- Build Your Own Ruby on Rails Web Applications [ILLUSTRATED]
- 在Ubuntu上安装Ruby On Rails
- Ruby on Rails 开发学习笔记 二
- Ruby on Rails(二) - 初探Ruby on Rails, 搭建一个博客项目并发布(草稿)
- Ruby——在Rails上使用Bootstrap
- 新人千万不要在 Windows 上使用 Ruby on Rails