これはかなり複雑な問題の説明です。私はいくつかの問題を解析しています。本当のものが見えないときには、 "組み合わせがなされたとき"に見えます。
それは...私は、最も簡単なアプローチは、データタスクではなく、Railsタスクとして検索を処理することだと思います。ちょうどあなたがあなたのテンプレートモデルのために必要な属性はどんな設定:
# In the migration
create_table templates do |t|
t.string :color # Set a validation for your hex codes, or whatever, in Rails
t.string :text
t.string :logo_file_name # These all assume you're using the Paperclip gem.
t.string :logo_content_type # (http://thoughtbot.com/projects/paperclip)
t.integer :logo_file_size # If you're tracking your logo attachment some other
t.datetime :logo_updated_at # way, do whatever's needed in that case.
end
はその後、モデルでは、さまざまなオプションのためのスコープ名前付きセット:
class Template < ActiveRecord::Base
has_attached_file :logo
named_scope :with_color, :conditions => {"color is not null"}
named_scope :with_text, :conditions => {"text is not null"}
named_scope :with_logo, :conditions => {"logo_file_name is not null"}
# You could add :without_ named scopes too, of course, if you needed them
end
は、その後、あなたは、単に何でも合うようにそれらを一緒に連鎖することができますユーザーが検索で確認したTemplate.with_color.with_text.with_logo
と指定されたスコープフィルタリングの最後には何も残っています。
それは意味がありますか?名前付きスコープは、この種のものにとっては非常に便利です。あなたが以前にそれらに出くわしたことがないなら、あなたはそれらの上のGoogleにしたいかもしれません。
は私にとってタグシステムのようです。 – palindrom