每天一剂Rails良药知识库


最近更新文章

每天一剂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) 有 1143 人浏览 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) 有 855 人浏览 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) 有 947 人浏览 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) 有 938 人浏览 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) 有 947 人浏览 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) 有 655 人浏览 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) 有 663 人浏览 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) 有 960 人浏览 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) 有 804 人浏览 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) 有 1090 人浏览 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) 有 656 人浏览 2011-05-26

每天一剂Rails良药之Adding Support for Localization

今天来看看Rails对于不同locale的支持,我们使用Globalize插件 ruby script/plugin install \ http://svn.globalize-rails.org/svn/globalize/globalize/trunk 然后我们生成migration文件 ruby script/generate globalize 然后运行 rake db:migr ...
hideto 评论 (0) 有 924 人浏览 2011-05-26

每天一剂Rails良药之Distributing Your Application As One Directory T

我们可以发布包含Rails源代码以及所有plugins的Rails程序,这样我们部署或迁移的时候就不用每次安装一次Rails以及依赖库 rake rails:freeze:gems表示把当前Gems安装的Rails Unpack到vendor/rails rake rails:unfreeze则表示删除vendor/rails 第三方Rails插件我们可以用ruby script\plugin in ...
hideto 评论 (0) 有 748 人浏览 2011-05-26

每天一剂Rails良药之Keeping Track of Who Did What

今天我们看看怎样在数据库记录用户操作 db/migrate/002_add_audit_trails_table.rb class AddAuditTrailsTable < ActiveRecord::Migration def self.up create_table :audit_trails do |t| t.column :record_id, :integer t.column ...
hideto 评论 (0) 有 859 人浏览 2011-05-26

每天一剂Rails良药之Easily Group Lists of Things

今天看看两个很好用的方法 1,Enumerable#group_by(): <% employees = Employee.find(:all).group_by{|employee| employee.title } %> <% employees.each do |title, people| %> <h2><%= title %></h2 ...
hideto 评论 (0) 有 948 人浏览 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