作者bypang (甚麽时候才等到你)
看板Ruby
标题Re: [问题] 如何以DRY的方式写code?
时间Wed Oct 7 16:09:29 2009
※ 引述《godfat (godfat 真常)》之铭言:
: 不介意的话可以这样试试看 @@ 前提当然是可以改 primary key 的话
: class Quotation < ActiveRecord::Base
: set_primary_key :doc_no
: end
: module QuotationsHelper
: def new_doc_no
: Quotation.last.doc_no + 1
: end
: end
我在想能不能在application helper里这麽做,因为有很多作业流程都需要用到
类似的编码方式。
例如
module ApplicationHelper
def new_doc_no
// 假想码
model_name.last.doc_no + 1
end
end
然後,进行Quotation流程时就会从quotations table中读取,而进行Invoice流程时
就会从invoices table中读取,这样就真的很“乾”(DRY)了XD
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.101.69.24
1F:推 godfat:有「乾」....到 XDD 狠一点!const_get(controller_name) 10/07 16:17