2011-05-12 34 views

回答

3

http://ar.rubyonrails.org/classes/ActiveRecord/Base.html

它也可以使用多個 屬性在相同的 找到他們與分離「和」等你拿 發現者像 Person.find_by_user_name_and_password 甚至 Payment.find_by_purchaser_and_state_and_country。 因此,而不是寫 Person.find的(:第一,:條件=> [ 「USER_NAME =和密碼=?」, USER_NAME,密碼]),你只是做 Person.find_by_user_name_and_password(USER_NAME, 密碼)。

+0

酷感謝.... – user730569 2011-05-12 23:34:37

0

作爲另一種解決方案,我認爲你可以嘗試組合幾個範圍。我的意思是你可能會使用一些分離的範圍來檢索一些數據,所以你不妨試一試。

因此,假設您有一個模型:

class YourModel < ActiveRecord::Base 
    scope :sent,where(:sent => true} 
    scope :by_param,lambda{|query| where("param= ?","#{query}")} 
end 

就用

YourModel.sent.by_par("something") 
相關問題