Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is a fairly complicated problem description. I'm having a little trouble parsing some of it -- e.g. "when a combination is made" -- in the absence of a real thing to look at. (And what does it have to do with storing images? Are your templates images?)</p> <p>That said... I'd say the simplest approach is to handle your searching as a Rails task rather than a data task. Just set whatever attributes you need for your Template model:</p> <pre><code># 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 </code></pre> <p>Then, in the model, set named scopes for the various options:</p> <pre><code>class Template &lt; ActiveRecord::Base has_attached_file :logo named_scope :with_color, :conditions =&gt; {"color is not null"} named_scope :with_text, :conditions =&gt; {"text is not null"} named_scope :with_logo, :conditions =&gt; {"logo_file_name is not null"} # You could add :without_ named scopes too, of course, if you needed them end </code></pre> <p>Then you can simply chain them together to match whatever the user checked in their search, e.g. <code>Template.with_color.with_text.with_logo</code> and you'll get whatever survives at the end of the named scope filtering.</p> <p>Does that make sense? Named scopes are very handy for this sort of thing -- you might want to Google on them if you haven't come across them before.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload