每天一剂Rails良药知识库


未分类文章

每天一剂Rails良药之Continuous Integration

Rails有一个简单的持续集成插件: ruby script/plugin install continuous_builder 不过这个插件是需要Subversion的 然后我们在repository/hooks目录下创建一个post-commit文件: #!/bin/sh DEVELOPERS=chad@chadfowler.com BUILDER="'Continuous Bu ...
hideto 评论 (0) 有 1782 人浏览 2011-05-26

每天一剂Rails良药之Automating Development With Your Own Generators

今天看看怎么写自己的Generators Rails在以下地方查找用户自定义的Generators: RAILS_ROOT/lib/generators RAILS_ROOT/vendor/generators RAILS_ROOT/vendor/plugins/any_subdirectory/generators ~/.rails/generators 以及以_generator为后缀的Gems ...
hideto 评论 (0) 有 1082 人浏览 2011-05-26

每天一剂Rails良药之Write Tests for Your Helpers

今天我们看看怎么测试我们的helper方法: require File.dirname(__FILE__) + '/../test_helper' class HelperTest < Test::Unit::TestCase include ActionView::Helpers::UrlHelper include ActionView::Helpers::TextHelper incl ...
hideto 评论 (0) 有 1025 人浏览 2011-05-26

每天一剂Rails良药之Testing Across Multiple Controllers

Rails测试分三种: 1,关注于一个单独的Model的单元测试Unit test 2,关注于一个单独的Controller和它使用的models之间的交互的功能测试Functional test 3,关注story级的多个controllers的多个actions之间的交互的集成测试Integration test 今天我们就来看看跨越多个controllers的集成测试 IntegrationT ...
hideto 评论 (0) 有 1214 人浏览 2011-05-26

每天一剂Rails良药之Extracting Test Fixtures From Live Data

Rails做单元测试时,我们自己手动去创建所有的fixtures会是个噩梦,有没有什么好的方案呢? 我们可以利用数据库里已有的数据,写一个rake tast来把数据库的数据复制出来到YAML文件里: CreateFixturesFromLiveData/lib/tasks/extract_fixtures.rake desc 'Create YAML test fixtures from data ...
hideto 评论 (0) 有 1137 人浏览 2011-05-26

每天一剂Rails良药之Creating Dynamic Test Fixtures

Rails的fixture文件在传递给YAML解析之前先用ERB解析,这样一来我们就可以使用Ruby代码动态生成测试数据,而不用一条数据一条数据的写了: <% 1.upto(50) do |number| %> child_post_<%= number %>: id: <%= number + 3 %> title: This is auto-generate ...
hideto 评论 (0) 有 906 人浏览 2011-05-26

每天一剂Rails良药之Manage a Static Site With Rails

对于静态站点我们可以利用Rails的cache来管理,如在controller中添加如下代码: after_filter {|c| c.cache_page} 这样将会对该controller的所有action作缓存 注意我们不要对UserProfile等页面做缓存,只对对所有用户一样的内容做缓存
hideto 评论 (0) 有 1217 人浏览 2011-05-26

每天一剂Rails良药之Write Code That Writes Code

很不幸我的2006-4-11版本的Rails Recipes的这章内容部分缺失 太晚了又没有找到更新的版本 记为not finished.
hideto 评论 (0) 有 1200 人浏览 2011-05-26

每天一剂Rails良药之Convert Your Sessions To ActiveRecord

我们看看config/environment.rb文件,其中有以下一段: # Use the database for sessions instead of the file system # (create the session table with 'rake db:sessions:create') # config.action_controller.session_store = : ...
hideto 评论 (0) 有 888 人浏览 2011-05-26

每天一剂Rails良药之Stud Out Authentication

登录和认证常常是我们Rails系统所必需的,但经常不是程序的核心功能 我们可以在ApplicationController里定义logged_in?方法: def logged_in? local_request? end helper_method :logged_in? 这样我们就可以在我们的Rails系统中的任何地方使用logged_in?方法 而且我们简单的用local_request? ...
hideto 评论 (0) 有 819 人浏览 2011-05-26

每天一剂Rails良药之Make your URLs Meaningful(and pretty)

这篇内容没什么价值,《Agile Rails》里的Routing Request一节讲述的比较详细了 ActionController::Routing::Routes.draw do |map| map.connect ':controller/service.wsdl', :action => 'wsd' map.connect ':controller/:action/:id' map ...
hideto 评论 (0) 有 1303 人浏览 2011-05-26

每天一剂Rails良药之Rendering CSV From Your Actions

有时候我们需要输出Comma Separated Values(CSV)等各种形式的输出来满足用户的需要: class ExportController < Application ontroller def orders content_type = if request.user_agent =~ /windows/i 'application/vnd.ms-excel' else 't ...
hideto 评论 (0) 有 1421 人浏览 2011-05-26

每天一剂Rails良药之Keep An Eye On Your Session Expiry

Rails的session默认为当用户关闭浏览器时终止 我们可以在config/environment.rb里设置它: CGI::Session.expire_after 1.month 这需要一个插件,具体session设置请参考http://wiki.rubyonrails.org/rails/pages/HowtoChangeSessionOptions 这不是今天我们讨论的重点 出于安 ...
hideto 评论 (0) 有 1762 人浏览 2011-05-26

每天一剂Rails良药之Cleaning Up Controllers with Post-back Actions

我们习惯与one-action-per-request,但是我们(特别是初学者)很容易被controller里的new(),create(),edit()和update()这些方法弄晕。 其实我们可以用一个方法来代替them all: def edit @recipe = Recipe.find_by_id(params[:id]) || Recipe.new if request.post? @ ...
hideto 评论 (0) 有 1414 人浏览 2011-05-26

每天一剂Rails良药之Role-Based Authorization

我们的系统往往并不只是靠登录这么简单来控制权限,今天我们来看看基于角色的授权 假设我们的系统已经建立了昨天的users表 1,migration class AddRolesAndRightsTables < ActiveRecord::Migration def self.up create_table :users_roles, :id => false do |t| t.col ...
hideto 评论 (0) 有 1411 人浏览 2011-05-26

知识库信息

最新评论

不能适应超过三层的的override,比如我有A,B,C三个模板,B在A的基础上添加自己的东西,C在B ...
mingliangfeng 评论了 Rails宝典之第八式: layout与content_for
讲的很清楚,赞
lixinso 评论了 ActionController::Resources + ActiveReso ...
这个插件的下载地址:https://github.com/rails/ssl_requirement
kaogua 评论了 每天一剂Rails良药之ssl_requirement
能评论吗???
refar 评论了 Rails宝典之第五十一式: will_paginate
<%= error_message_on "post", "ti ...
fcp6316 评论了 Rails宝典之第六十五式: Stopping spam
rake db:fixtures:load # Load fixtures into the cur ...
xu_ch 评论了 Rails宝典八十一式:Rails2.0之Fixtures尝 ...
[/b][i][/i][u][/u]引用[color=red][/color][size=medium ...
linjie_830914 评论了 Rails源码研究之ActionController:二,ro ...
并行工程环境的面向成本设计
libiun 评论了 Rails宝典八十五式:YAML配置文件
...
xu_ch 评论了 Rails宝典之第五十七式: Select or Create
你老好了,找的就是他了
xu_ch 评论了 Rails宝典之第七式: layout详解
Global site tag (gtag.js) - Google Analytics