最新文章列表

Rails 自身的many to many关系 self has_many

简单点的 #注意外键在person上people: id; name; whatever-you-need friendships: id; person_id; friend_id class Person < ActiveRecord::Base has_many :friendships, :foreign_key => "person_id", ...
夜鸣猪 评论(0) 有2681人浏览 2011-11-12 01:43

【译】rails的嵌套属性(Nested Attributes)使用

  Active Record Nested Attributes 通过嵌套属性(nested attribute),你可以通过parent来保存与其相关联的属性。默认情况下,嵌套属性是关闭的,你可以开启accepts_nested_attributes_for这个类方法,就在该model上生成一个属性writer。 属性writer是以该关联命名。例如,为你的model增加两个新方法 ...
genius_45 评论(0) 有3878人浏览 2011-11-06 19:54

Ruby面试系列四,新鲜刚出炉的面试题

这次是留的家庭作业 引用 Write a model (ActiveRecord-based, or similar pattern) for storing configuration settings. Each setting should have a unique identifier such as a name, and should hold a single value. Fo ...
夜鸣猪 评论(2) 有1943人浏览 2011-10-13 04:47

Active Record batch processing in parallel processes

Active Record 提供 find_each来分批处理大量数据. 但是,当数据量在百万级别或是更多的时候find_each也会变得很慢。 采用像Resque这样的异步处理插件是一个不错的选择: User.find_each {|user| Resque.enqueue(MyJob, user) } 但是用Resque有时候又有点杀鸡用牛刀的嫌疑,使用forking! if G ...
Hooopo 评论(0) 有2229人浏览 2011-10-07 01:20

Rails Study(9)Associations First Part

Rails Study(9)Associations First Part 1. Why Associations? Without Associations, we will configure and use the models like this: class Customer < ActiveRecord::Base end class Order < ActiveRecor ...
sillycat 评论(0) 有1129人浏览 2011-08-07 23:01

Rails Study(VII)Validations and Callbacks

Rails Study(VII)Validations and Callbacks 1. The Object Life Cycle Validations allow you to ensure that only valid data is stored in database. Callbacks and observers allow you to trigger logic before ...
sillycat 评论(0) 有1077人浏览 2011-08-06 22:36

如何自定义处理ActiveRecord中的errors信息

今天写代码的时候,客服MM向我反馈了一个问题,这个问题本身是很容易解决的,但是出现这个问题时的提示信息有些令人郁闷,ActiveRecord的信息显示在页面时,只看到了一堆I18n无法找到相应语言下定义的提示信息。 但是我的应用支持中文和英文,我仔细检查了locales下的en.yml和zh-CN.yml,明明是有配置相应的提示信息的,却显示无法找到。一番检查之后,我认为问题在于文件加载先后顺序的 ...
yangzhihuan 评论(3) 有2822人浏览 2011-07-26 23:33

Rails路由 转摘

此文原文在http://guides.rubyonrails.org/routing.html。这是我根据自己的理解作的一些笔记。 1 使用路由有两上目的 1.1 连接URLs 当Rails应用收到HTTP的请求时,Rails会响应 GET /patients/17 Rails中的路由引擎是一个代码片断。在这个例子中,可能会运行patients控制器的show方法。显示ID为17的详细信息。 ...
虫子樱桃 评论(0) 有813人浏览 2011-06-24 17:13

RUBY_RAILS 使用转载:活动记录纵览

使用活动记录的步骤  虽然使用活动记录映射数据表不需要复杂的设置,但我们必须按着活动记录所制定的规范进行操作。这些规范将成为活动记录工作的一部分,以下就是使用活动记录的步骤。  1.建立表  2.连接数据库  3.建立ORM  4.进行增、删、改操作  第一步需要完全按着规范来做。建立表的过程一定要严格按着规范进行,否则就会覆盖活动记录的默认值。以下是建立表的详细过程:   ·建立表  如果你不想在 ...
lx13345 评论(0) 有809人浏览 2011-06-22 20:13

rails异常(错误)处理

方法1:http://www.uedidea.com/rails%E9%94%99%E8%AF%AF%E5%A4%84%E7%90%86.html   def add_to_cart product = Product.find(params[:id]) rescue ActiveRecord::RecordNotFound #拦截Product.find()异常 logger.error ...
RunUpwind 评论(0) 有5843人浏览 2011-06-22 15:04

rails api 有用的链接

完全给自己用的 http://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html ActiveRecord::QueryMethods ActiveRecord::FinderMethods ActiveRecord::NestedAttributes::ClassMethods ActiveRecord ...
夜鸣猪 评论(0) 有1050人浏览 2011-06-22 01:52

PHP 5.4 全新 trait 语法

PHP 5.4 全新 trait 语法 文章转载于:http://blog.makingware.com/?p=97 发表于 2011 年 06 月 08 日 由 Jeffrey Au <!-- .entry-meta --> 最近看 PHP 5.4 的 Changelog 时发现新增了 Trait 语法,根据 wiki 的说明,这个语法是为了解决代码的“水平复用”而诞生 ...
liuleiluwenhui 评论(1) 有714人浏览 2011-06-18 19:29

多个外键指向一个模型

多个外键指向一个模型,比较极端的例子: http://stackoverflow.com/questions/307581/rails-model-has-many-with-multiple-foreign-keys class Person < ActiveRecord::Base belongs_to :father, :class_name => 'Person' ...
varding 评论(0) 有908人浏览 2011-06-15 11:06

用RUBY测试数据转移(存储过程之类的)

基于Ruby Test Unit和Rails ActiveRecord 备忘用的 require 'test/unit' require 'rubygems' require 'active_record' require 'logger' #建立基本的数据库链接 ActiveRecord::Base.establish_connection( :adapter =& ...
cxh116 评论(0) 有1131人浏览 2011-06-13 15:35

Identity Map in Rails3.1

Identity Map是Rails3.1的又一个新特性。 一、什么是Identity Map 引用Identity Map is a design pattern that: Ensures that each object gets loaded only once by keeping every loaded object i ...
Hooopo 评论(1) 有2708人浏览 2011-06-12 18:29

rails3定制404和500错误

在application_controller.rb 中使用rescue_from 可以完成大部分工作: 01 class ApplicationController < ActionController::Base02   03   def self.rescue_errors04     rescue_from Exception,                     ...
DerekMorgan 评论(0) 有2358人浏览 2011-06-10 20:38

用concerns来管理models

# autoload concerns module YourApp   class Application < Rails::Application     config.autoload_paths
DerekMorgan 评论(0) 有954人浏览 2011-06-10 11:07

rails3 session配置

Use the database for sessions instead of the cookie-based default, which shouldn't be used to store highly confidential information Create the session table with rake db:sessions:create   Run the ...
RunUpwind 评论(0) 有2249人浏览 2011-06-09 19:56

dataview的使用

使用1 /*!* Ext JS Library 3.3.1* Copyright(c) 2006-2010 Sencha Inc.* licensing@sencha.com* http://www.sencha.com/license*/Ext.onReady(function(){ var xd = Ext.data; var store = new Ext.data.JsonStor ...
isiqi 评论(0) 有1445人浏览 2011-04-04 18:10

EhLib使用攻略

转贴:EhLib使用全攻略 KeyLife富翁笔记 作者: archonwang标题: Ehlib 的使用 关键字: 前 言 分类: 个人专区 密级: 公开 (评分:★★★ , 回复: 10, 阅读: 4649) &raquo;&raquo; 最近闲来无事,就装了一个 Ehlib 来玩。呵呵,没想到,这么个小东西一下子就把我迷住了,细细品来,的确是一个非常好的控件作品。作 ...
isiqi 评论(0) 有3237人浏览 2009-04-07 13:57

最近博客热门TAG

Apache(33931) Lucene(5053) Hadoop(5049) nginx(3449) vim(3262) GCC(2954) memcached(2625) jfreechart(1688) Django(1602) Zend(1413) ActiveMQ(1398) Grails(1374) ActiveRecord(1349) OpenSource(1236) Emacs(870) Glassfish(858) lighttpd(810) rubygems(716) GAE(631) Blend(516)

博客人气排行榜

    博客电子书下载排行

      >>浏览更多下载

      相关资讯

      相关讨论

      Global site tag (gtag.js) - Google Analytics