看板 Ruby 關於我們 聯絡資訊
環境: Ruby 1.8.7 Rails 2.3.4 狀況: 我寫的是一個企業管理程式,在每開一個新的作業流程都會先取得一個新的編號 (不是預設的id)。例如Quotation,我在Quotations Helper里是這樣寫: module QuotationsHelper def new_doc_no Quotation.find(:first, :order => 'doc_no DESC').doc_no + 1; end end 至于其他的作業流程是否也要寫類似的helper function,還是有更DRY的方式? 謝謝指教 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.101.213.59
shelary:這樣寫在有很多人同時使用時會有問題。doc_no有可能重覆 10/07 11:29
bypang:在正式寫入database時會用transaction檢查一遍,再寫入 10/07 11:47
bypang:然後會用一個alert告知使用者doc_no已經修改了 10/07 11:48