Hello,
I’m trying the search method used in the Guides:
and I don’t know what is coming back to the controller when a text box
is empty. When each of the 2 text boxes (described below) have a
value then the search works. However, if the second box is empty then
nothing is returned, even though there is data to match the first box.
The boxes are formed in the search.html.erb as:
<%= form_tag({controller => “people”, :action => “search”}, :method =>
“get” ) do %>
<%= label_tag(:skill1, “Search Skills for:”) %>
<%= text_field_tag(:skill1) %>
<%= text_field_tag(:skill2) %>
<%= submit_tag(“Search”) %>
<% end %>
And are read in the controller by:
def search
@people = Person.all
@skill_search1 = String.new
@skill_search1=:skill1.to_s
@skill_search2 = String.new
@skill_search2=:skill2.to_s
if @skill_search2.empty?
@found_people = Person.where("skill_set LIKE ?",
params[@skill_search1])
else
@found_people = Person.where(“skill_set LIKE ? and skill_set
LIKE ?”, params[@skill_search1],params[@skill_search2])
end
end
I have also tried: if @skill_search2 == NUL, == " ",== nil,
==‘’ and =“” under the theory that if you type in everything then
something might work (hey, it’s worked in the past!).
Looking at the output in the command window that is used for the
“rails server” call to WEBRick it seems that the second conditional
option is always called and the statement ends in “and skill_set LIKE
‘’” (that is 2 apostrophes before the final quote and, while it’s a
little hard to judge, I don’t think there is a space between the
apostrophes).
So the question is: what is being returned by the blank text box
and how should it be checked?
Thanks,
Barney