Hej You probably should check the params hash in the controller:
@skill_search1 = params[:skill1] etc.. Also use a debugger call in the search method to see the parameters that are passed def search debugger . . end Cheers, Eric On 28 jul 2011, at 22.03, Barney wrote: > Hello, > I'm trying the search method used in the Guides: > http://guides.rubyonrails.org/form_helpers.html > 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 > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.