-1
class Anketum < ActiveRecord::Base
has_one :user
class << self
def search(params)
self.scope :h, :conditions => {:height => params[:height]}
#scope :w, :conditions => {:width => params[:width]}
self.h if params[:height]
end
end
end
はのparamsに依存レール[:XXX]:複数のスコープは、私は、複数のスコープを作成する必要が
# app/models/anketum.rb
class Anketum < ActiveRecord::Base
end
# app/controller/some_controller.rb
def search
@results = Anketum.scoped
[:width, :height, :any, :other, :searchable, :attribute].each do |key|
@results.where(key => params[key]) if params[key].present?
end
end
あなたの存在
奇妙なSELECT "anketa"。* FROM "anketa" ' –
dbテーブルは" anketa "とも呼ばれますか?そうでない場合は、セットアップに非常に間違ったことがあります。 – coreyward
あなたはどちらのバージョンのレールですか?私は 'named_scope'の代わりに' scope'を使っているので3と仮定しました。 – coreyward