![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
rails
文章平均质量分 65
iteye_2251
这个作者很懒,什么都没留下…
展开
-
activerecord查询joins选项使用范例
示例相关需求: 在处方列表中显示病人姓名(处方关联到就诊记录,就诊记录关联到病人)[code="ruby"]class Prescription < ActiveRecord::Base belongs_to :patient_case_detail has_one :patient_case, :through => :patient_case_detailendP...2009-12-18 16:39:08 · 117 阅读 · 0 评论 -
rails模板布局学习笔记
一、如何渲染1、如有以下控制器[code]BooksController def show @book = Book.find(params[:id]) endend[/code]Rails将自动渲染 app/views/books/show.html.erb2、事实上,如果你设置了捕获所有路由 map.connetc ':controller/:ac...原创 2009-07-15 18:31:37 · 162 阅读 · 0 评论 -
named_scope
[code="ruby"]class Website < ActiveRecord::Base named_scope :recent, lambda{ |limit| {:order => "created_at DESC",:limit => limit} }endWebsite.newest 3 #返回最新的三条记录[/code]...原创 2008-12-05 13:09:14 · 86 阅读 · 0 评论 -
rails查询学习笔记
教程原文[url]http://guides.rubyonrails.org/active_record_querying.html[/url]1、获取数据.获取第一条、最后一条记录[code="ruby"]Model.firstModel.first(options)Model.find(:first, options)Model.lastModel.last...原创 2009-07-31 15:09:34 · 99 阅读 · 0 评论 -
rails控制器学习笔记
教程原文[url]http://guides.rubyonrails.org/action_controller_overview.html[/url].Array参数Get /clients?ids[]=1&id[]=2&id[]=3params[:ids]=["1", "2", "3"].Hash参数[code="html"] ...原创 2009-08-04 18:50:38 · 130 阅读 · 0 评论 -
rails关联学习笔记
[url]http://guides.rubyonrails.org/association_basics.html[/url]1、为什么要关联?为什么我们需要在两个model之间建立关联?因为它让通用操作变得简单和容易。例如,考虑有一个rails应用程序包含一个customer model和一个order model。每一个customer有很多的order。没有关联时,model声明如...2009-08-17 18:06:41 · 140 阅读 · 0 评论