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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Eric, I''m using Scite and there doesn''t seem to be a debugger in it. How else would I check that hash? But, could you tell me what form (type, value) is the return from that empty text box? Thanks, Barney On Jul 28, 4:59 pm, Eric Björkvall <eric.bjorkv...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hej Barney The debugger call will stop the execution and drop you into the debugger - it''s not from within your text editor - it''s in the terminal window where you run your app Start your app with rails server --debugger or (if your running rails < 3.0 ) script/server --debugger Cheers, Eric On 29 jul 2011, at 00.59, Barney wrote:> Hi Eric, > I''m using Scite and there doesn''t seem to be a debugger in it. > How else would I check that hash? > But, could you tell me what form (type, value) is the return from > that empty text box? > Thanks, > Barney > > > On Jul 28, 4:59 pm, Eric Björkvall <eric.bjorkv...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> For more options, visit this group athttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Jul 28, 2011 at 3:59 PM, Barney <bsperlin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> How else would I check that hash?Besides the previously mentioned debugger, you can add logging statements to your code to provide more information.> But, could you tell me what form (type, value) is the return from > that empty text box?It''s the web -- all request parameters are strings; if no value was set in the client then it''s an empty string. But based on the code above -- ------ @skill_search2 = String.new # blech - extraneous @skill_search2=:skill2.to_s # ditto, also meaningless :-) if @skill_search2.empty? ------ what you want is just if params[''skill2''].empty? HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Eric, I didn''t know about the debugger. When I ran: rails server --debugger I got the error that I needed to install ruby-debug with ''gem install ruby-debug'' but when I did the error: "Failed to build gem native extension." and then there were a bunch of errors involving "no member" in RArray and RString. I then successfully installed ruby-debug-ide19-0.4.12, "but the rails server --debugger" gave the same error as before. Maybe I need to ask this in a separate question, but if you know the answer to the problem off- hand I''d appreciate knowing it. Thanks, Barney On Jul 28, 7:09 pm, Eric Björkvall <eric.bjorkv...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hej Barney > > The debugger call will stop the execution and drop you into the debugger - it''s not from within your text editor - it''s in the > terminal window where you run your app > > Start your app with > > rails server --debugger > > or (if your running rails < 3.0 ) > > script/server --debugger > > Cheers, > Eric > > On 29 jul 2011, at 00.59, Barney wrote: > > > Hi Eric, > > I''m using Scite and there doesn''t seem to be a debugger in it. > > How else would I check that hash? > > But, could you tell me what form (type, value) is the return from > > that empty text box? > > Thanks, > > Barney > > > On Jul 28, 4:59 pm, Eric Björkvall <eric.bjorkv...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > >>> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >>> For more options, visit this group athttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Hassan, the code changed you mentioned above worked! I appreciate your taking the time to help me, Barney On Jul 28, 7:25 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Jul 28, 2011 at 3:59 PM, Barney <bsper...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > How else would I check that hash? > > Besides the previously mentioned debugger, you can add logging > statements to your code to provide more information. > > > But, could you tell me what form (type, value) is the return from > > that empty text box? > > It''s the web -- all request parameters are strings; if no value was set > in the client then it''s an empty string. > > But based on the code above -- > ------ > @skill_search2 = String.new # blech - extraneous > @skill_search2=:skill2.to_s # ditto, also meaningless :-) > > if @skill_search2.empty? > ------ > what you want is just > > if params[''skill2''].empty? > > HTH, > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe80Tx58lXaADg@public.gmane.org://about.me/hassanschroeder > twitter: @hassan-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.