Hey, I have a main page that lists a table of Devices, along with a Search box. I''d like to have the Search field pull up any related Devices, and then re-populate the table. I can do this without AJAX, just calling my List action over again, passing the params to search on, but with AJAX I get the error, "Cannot convert nil to string" on this line: @device_pages, @devices = paginate( :devices, :conditions => ["description like ?",''%''+params[:description]+''%''], :per_page => 10) It is falling apart on the ''+'' portion. Can anybody help with the process of this? All the AJAX examples I''ve seen only render one line of text, not a whole group of dynamic text. ---------------- My List html: <%= form_remote_tag(:update => "results", :url => { :action => :search }, :position => "bottom" ) %> <%= text_field_with_auto_complete :device, :description %><br/> <p><label for="description">Description</label><br/> <%= submit_tag "Search" %> <%= end_form_tag %> <% if params[:description] %> <h1>Results for ''<%=h params[:description] %>''</h1> <% end %> <table id="results"> </table> --------------- My ''search'' rhtml: <% for device in @devices %> <tr> <td><%=h device.make %></td> <td><%=h device.model %></td> <td><%=h device.description %></td> <td><%= device.person.fname %> <%= device.person.lname %></td> </tr> <% end %> -------------------------- My DevicesController for the two actions: def list device_pages, @devices = paginate :devices, :per_page => 10 end def search @device_pages, @devices = paginate( :devices, :conditions => ["description like ?",''%''+params[:description]+''%''], :per_page => 10) end -- - Nic
Does your params hash have a key of :description? Check what the params are in log/development.log. My guess is you want params[:device][:description] in your search action. -Jonny Nic Werner wrote:> Hey, > > I have a main page that lists a table of Devices, along with a Search > box. I''d like to have the Search field pull up any related Devices, > and then re-populate the table. > > I can do this without AJAX, just calling my List action over again, > passing the params to search on, but with AJAX I get the error, > "Cannot convert nil to string" on this line: > > @device_pages, @devices = paginate( :devices, > :conditions => ["description like > ?",''%''+params[:description]+''%''], > :per_page => 10) > > It is falling apart on the ''+'' portion. Can anybody help with the > process of this? All the AJAX examples I''ve seen only render one line > of text, not a whole group of dynamic text. >-- Posted via http://www.ruby-forum.com/.
Thanks Jonathan, I figured out later that my problem is accessing the params correctly. I''m still having trouble though: I tried this: if params[:device][:description] and I get ''Symbol as Array'' If I put parentheses: if params([:device][:description]) You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occured while evaluating nil.[] The API wasn''t too helpful on accessing nested params, any ideas? - Nic. On 1/25/06, Jonathan Viney <jviney@spreydon.org.nz> wrote:> Does your params hash have a key of :description? Check what the params > are in log/development.log. > > My guess is you want params[:device][:description] in your search > action. > > -Jonny > > Nic Werner wrote: > > Hey, > > > > I have a main page that lists a table of Devices, along with a Search > > box. I''d like to have the Search field pull up any related Devices, > > and then re-populate the table. > > > > I can do this without AJAX, just calling my List action over again, > > passing the params to search on, but with AJAX I get the error, > > "Cannot convert nil to string" on this line: > > > > @device_pages, @devices = paginate( :devices, > > :conditions => ["description like > > ?",''%''+params[:description]+''%''], > > :per_page => 10) > > > > It is falling apart on the ''+'' portion. Can anybody help with the > > process of this? All the AJAX examples I''ve seen only render one line > > of text, not a whole group of dynamic text. > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- - Nic
Can you post the raw params hash straight from the log file? -Jonny. Nic Werner wrote:> Thanks Jonathan, I figured out later that my problem is accessing the > params correctly. I''m still having trouble though: > > I tried this: if params[:device][:description] > > and I get ''Symbol as Array'' > > If I put parentheses: if params([:device][:description]) > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occured while evaluating nil.[] > > The API wasn''t too helpful on accessing nested params, any ideas? > > - Nic. >-- Posted via http://www.ruby-forum.com/.
Processing DevicesController#search (for 127.0.0.1 at 2006-01-25 11:31:04) [POST] Parameters: {"device"=>{"description"=>"color"}, "commit"=>"Search", "action"=>"search", "controller"=>"devices"} On 1/25/06, Jonathan Viney <jviney@spreydon.org.nz> wrote:> Can you post the raw params hash straight from the log file? > > -Jonny. > > Nic Werner wrote: > > Thanks Jonathan, I figured out later that my problem is accessing the > > params correctly. I''m still having trouble though: > > > > I tried this: if params[:device][:description] > > > > and I get ''Symbol as Array'' > > > > If I put parentheses: if params([:device][:description]) > > > > You have a nil object when you didn''t expect it! > > You might have expected an instance of Array. > > The error occured while evaluating nil.[] > > > > The API wasn''t too helpful on accessing nested params, any ideas? > > > > - Nic. > > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- - Nic
You should be able to access that description value of ''color'' with: params[''device''][''description''] -Jonny. Nic Werner wrote:> Processing DevicesController#search (for 127.0.0.1 at 2006-01-25 > 11:31:04) [POST] > Parameters: {"device"=>{"description"=>"color"}, "commit"=>"Search", > "action"=>"search", "controller"=>"devices"} > > On 1/25/06, Jonathan Viney <jviney@spreydon.org.nz> wrote: >> > and I get ''Symbol as Array'' >> > >>-- Posted via http://www.ruby-forum.com/.
It ended up working as @params[:device][:description], thanks for your help. On 1/26/06, Jonathan Viney <jviney@spreydon.org.nz> wrote:> You should be able to access that description value of ''color'' with: > > params[''device''][''description''] > > -Jonny. > > Nic Werner wrote: > > Processing DevicesController#search (for 127.0.0.1 at 2006-01-25 > > 11:31:04) [POST] > > Parameters: {"device"=>{"description"=>"color"}, "commit"=>"Search", > > "action"=>"search", "controller"=>"devices"} > > > > On 1/25/06, Jonathan Viney <jviney@spreydon.org.nz> wrote: > >> > and I get ''Symbol as Array'' > >> > > >> > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- - Nic
Jonathan Viney
2006-Jan-26 22:44 UTC
[Rails] Re: Re: Re: Re: AJAX Search w/database results
Are you using Rails 1.0? Nic Werner wrote:> It ended up working as @params[:device][:description], thanks for your > help.> > > -- > - Nic-- Posted via http://www.ruby-forum.com/.
Yep. gem list: .... rails (1.0.0) ... On 1/26/06, Jonathan Viney <jviney@spreydon.org.nz> wrote:> Are you using Rails 1.0? > > Nic Werner wrote: > > It ended up working as @params[:device][:description], thanks for your > > help. > > > > > > > -- > > - Nic > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- - Nic
Jonathan Viney
2006-Jan-27 12:50 UTC
[Rails] Re: Re: Re: Re: Re: AJAX Search w/database results
Strange, you shouldn''t have to use @params, params by itself should work fine. Oh well, just one of those strange things that makes life interesting ;) -Jonny Nic Werner wrote:> Yep. > > gem list: > .... > rails (1.0.0) > ... >-- Posted via http://www.ruby-forum.com/.