每天一剂Rails良药知识库


未分类文章

每天一剂Rails良药之javascript_test

今天来看看javascript_test这个Rails plugin,它是对script.aculo.us库的单元测试框架的Rails风格测试封装 下载安装后,我们可以使用ruby script/generate javascript_test foo来对public/javascripts/foo.js生成测试用的html文件 在测试用的html文件里我们可以写对JavaScript的测试,语法见 ...
hideto 评论 (0) 有 1112 人浏览 2011-05-26

每天一剂Rails良药之http_authentication

今天我们来看看Rails的HTTP Basic认证插件http_authentication 安装该插件后我们写一个TestController来看看效果: class TestController < ApplicationController USER_NAME, PASSWORD = "dhh", "secret" before_filter : ...
hideto 评论 (0) 有 998 人浏览 2011-05-26

每天一剂Rails良药之exception_notification

每天一剂Rails良药之Getting Notified of Unhandled Exceptions中也提到了Exception Notification插件 该插件在production环境下,当程序出错时会给recipient发送notification邮件 Exception notification只会在访问的IP地址不为local时才工作,我们可以配置认为是local的IP: co ...
hideto 评论 (0) 有 915 人浏览 2011-05-26

每天一剂Rails良药之continuous_builder和deadlock_retry

continuous_builder是一个Rails与Subversion集成的持续集成工具,参考http://hideto.iteye.com/blog/80873 deadlock_retry允许数据库驱动重试死锁的事务,它已经自动集成到ActiveRecord,我们不用更改任何代码就拥有该插件的重试事务的功能
hideto 评论 (0) 有 708 人浏览 2011-05-26

每天一剂Rails良药之atom_feed_helper

前面的一篇文章每天一剂Rails良药之Syndicate Your Site With RSS中我们看了怎样手动创建RSS 今天我们来看看Rails开发组提供的一个atom_feed_helper插件,它使得创建atom feeds更容易 首先安装atom_feed_helper插件 ruby script/plugin install atom_feed_helper 我们来看看源码,首先 ...
hideto 评论 (0) 有 1149 人浏览 2011-05-26

每天一剂Rails良药之account_location

《Rails Recipes》已经告一段落,今天开始一起学习Rails插件 首先安装我们今天要看的account_location插件: ruby script/plugin install account_location account_location很简单,就是几个helper方法,我们先看看源码: # Copyright (c) 2005 David Heinemeier Hanss ...
hideto 评论 (0) 有 859 人浏览 2011-05-26

每天一剂Rails良药之Handling Bounced Email

当Email发送失败时,我们可以捕获bounced messages来notify系统用户邮件发送出错 app/models/reminder.rb class Reminder < ActionMailer::Base def reminder(recipient, text) @subject = 'Automated Reminder!' @body = {:text => te ...
hideto 评论 (0) 有 949 人浏览 2011-05-26

每天一剂Rails良药之Sending Email With Attachments

今天来看看使用Rails发送带附件的邮件 Controller app/controllers/spam_controller.rb: class SpamController < ApplicationController def spam Spammer.deliver_spam_with_attachment(params[:name], params[:email], params[ ...
hideto 评论 (0) 有 941 人浏览 2011-05-26

每天一剂Rails良药之Testing Incoming Email

今天来看看Rails对接收Email的测试,首先ruby script/generate mailer Receiver,Rails会自动为我们生成test/unit/receiver_test_pristine.rb: require File.dirname(__FILE__) + '/../test_helper' require 'receiver' class ReceiverTest ...
hideto 评论 (0) 有 950 人浏览 2011-05-26

每天一剂Rails良药之Send Gracefully Degrading Rich-Content Emails

针对网页浏览器和手机,我们的Email的content_type分别为"text/html"和"text/plain" 我们可以这样做ruby script\generate mailer Notifier multipart_alternative app/models/notifier.rb: def multipart_alternative(reci ...
hideto 评论 (0) 有 663 人浏览 2011-05-26

每天一剂Rails良药之Adding Simple Web Serices To Your Actions

1,对于接收WebService,我们完全不用管,因为默认时任何ContentType为"application/xml"的POST都将被Rails内建的XmlSimple解析并转换为参数的Hash,这样我们就始终可以在controller里使用params方法得到参数 2,对于返回WebService,可以这样做 app/controllers/contacts_control ...
hideto 评论 (0) 有 664 人浏览 2011-05-26

每天一剂Rails良药之Easy HTML Whitelists

有时候我们可能要允许用户使用某些HTML标签,但是必须禁止另外一些HTML标签 我们可以在数据库存储用户输入的内容,包括允许的HTML标签,然后显示时过滤一下 让我们来一个helper方法来过滤内容,有两种方式: 1,写在application_helper.rb里 2,写在lib目录里,然后在config/environment.rb里加上require_dependency 'rails_pat ...
hideto 评论 (0) 有 964 人浏览 2011-05-26

每天一剂Rails良药之Validating Non-ActiveRecord Objects

对于非ActiveRecord对象的Validation,我们不能简单的include ActiveRecord::Validations 我们需要写一个module,如ValidatingNonARObjects/lib/validateable.rb module Validateable [:save, :save!, :update_attribute].each{|attr| defin ...
hideto 评论 (0) 有 809 人浏览 2011-05-26

每天一剂Rails良药之Automatically Save a Draft of a Form

今天我们来看看Gmail里的Ajax自动保存草稿在Rails里的实现 首先在layout里引入Javascript标签 [coce] <%= javascript_include_tag :defaults %> posts_controller.rb def new if request.get? @post = session[:post_draft] || Post.new ...
hideto 评论 (0) 有 1095 人浏览 2011-05-26

每天一剂Rails良药之The Console Is Your Friend

我们要多使用ruby script/console,在开发Rails程序时最好启动一个console窗口 我们来看看我们可以使用console干什么: Person.find_by_first_name("Chad").email Calendar.column_names app.get "/" app.follow_redirect! 如果Ruby编译 ...
hideto 评论 (0) 有 657 人浏览 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