8f5553306c2cf7f4b14153f6117f8e9b

Any help is appreciated.

def build_criteria(data_cols, i)
     filterHTML = ''
     typeObjects = ''
     data_cols.each do |d|
       typeObjects += "<option value='#{d}'>#{d}</option>"
     end

     filterHTML += "<div id='additionalcriteria#{i}'>"
     filterHTML +=  "<select name='dataType#{i}'>#{typeObjects}</select>"
     filterHTML += select_tag ("operator#{i}", "
                                 <option value='<'>is less than</option>
                                 <option value='<='>is less than or equal to</option>
                                 <option value='=='>is equal to</option>
                                 <option value='>='>is greater than or equal to</option>")
     filterHTML += text_field_tag("value#{i}")
     filterHTML += "</div>"
end

Refactorings

No refactoring yet !

6f348c571c100b4e49500d52d6e67bcc

Josh N. Abbott

April 23, 2009, April 23, 2009 21:34, permalink

1 rating. Login to rate!

Here's what I came up with quickly. You may need to tweak it a bit, but it should give you an idea of what I'm going for.

Hope this helps!

-- Josh

def build_criteria(data_cols, i)
  OPERATOR_OPTIONS = [
                       ['<', 'is less than'],
                       ['<=', 'is less than or equal to'],
                       ['==', 'is equal to'],
                       ['>=', 'is greater than or equal to']
                     ]

  returning filter_html = String.new do |html|
    html += select_tag("dataType#{i}", options_for_select(data_cols))
    html += select_tag("operator#{i}", options_for_select(OPERATOR_OPTIONS))
    html += text_field_tag("value#{i}")
  end
  content_tag(:div, filter_html, :id => "additional_criteria#{i}")
end
8f5553306c2cf7f4b14153f6117f8e9b

Danny Peck

April 23, 2009, April 23, 2009 21:44, permalink

No rating. Login to rate!

Thanks Josh. Looks nice.

8f5553306c2cf7f4b14153f6117f8e9b

Danny Peck

April 23, 2009, April 23, 2009 22:29, permalink

No rating. Login to rate!

Looks nice. BTW, the "all caps" OPERATOR_OPTIONS didn't jive with Ruby because it thought it was a constant. Also, within the operator_options, the values are reversed. The first '' will be what appears in the dropdown to the user. The second '' is the actual value.

A8d3f35baafdaea851914b17dae9e1fc

Adam

April 23, 2009, April 23, 2009 22:37, permalink

1 rating. Login to rate!
def build_criteria(columns, i)
  content_tag(:div, :id => "additionalcriteria#{i}") do
    select_tag("dataType#{i}", options_for_select(columns)) +
    select_tag("operators#{i}", options_for_select(OPERATOR_OPTIONS)) +
    text_field_tag("value#{i}")
  end
end
36aef9956c6082f69622dd67e8da376f

Josh

April 24, 2009, April 24, 2009 06:39, permalink

No rating. Login to rate!

Yep, all caps is a Ruby constant and that's what I was going for. And, oops. Sorry. You're right, the first element in the array is what the user sees, and the second is the option value.

Your refactoring





Format Copy from initial code

or Cancel