두 필드를 조합하여 주어진 모델의 모든 값을 찾으려고합니다.Ruby on Rails, 두 조건으로 찾기
나는 다음과 같은 모델이 있습니다
create_table "users", :force => true do |t|
t.string "name"
t.string "url"
t.integer "clicks_given"
t.integer "clicks_received"
t.datetime "created_at"
t.datetime "updated_at"
end
을 나는 모델이 방법 정의 :
def credits
credits = self.clicks_given - self.clicks_received
end
나는 주어진 크레딧 위의 모든 사용자를 찾기 위해 노력하고 있어요 :
@users = User.find(:all, :conditions => { "credits >= ?", -5 })
을
및 :
@users = User.find(:all, :conditions => { "clicks_given - clicks_received >= ?", -5 })
실패. 올바른 사용자를 찾기 위해 올바른 진술은 무엇입니까?
감사합니다. 아직 RoR에 익숙하지 않습니다. 배열의 경우 []와 해시의 경우 {} 사이의 차이점을 알지 못했습니다. 감사합니다 –
그 경우, 레일 가이드는 가장 친한 친구입니다 : http://guides.rubyonrails.org/active_record_querying.html :) – Thilo
너, 내가 가끔 거기에 간다. 그러나 대부분의 시간에 나는 내가 무엇인지 모른다. 그래서 내가 묻는 결국 찾고있어. :) –