Topic: Problems deploying

Recently I tried viewing my app on Mozilla Firefox using the Webrick server. Firefox displays most of the pages, however when I use AJAX and RJS to display a search result below the search criteria box, the search result page does not display. Looking in the development.log, there is an error "The error occured while evaluating nil.[]". All this works perfectly fine on IE (the results are shown below the search criteria box).

Then I setup Apache. Viewing the app through IE worked fine. However, when AJAX and RJS were used to display a search result below the search criteria box, nothing is displayed. Looking in the development.log, I see that the results are returned properly:
"Rendered search/_orders (0.15700)
Completed in 3.57800 (0 reqs/sec) | Rendering: 2.20300 (61%) | DB: 1.12500 (31%) | 200 OK [http://xpjammer/dashboard/search/submit]"

_orders is the page that should display below my search criteria page. Even though the log says the page is rendered properly, the page is not displaying.

I then tried accessing the app on Firefox, and again the log showed the error "The error occured while evaluating nil.[]"

I am just wondering if anyone else has seen this sort of pattern. Since I will be using Apache for my production environment, I need to solve the problem soon.

Thank you for any help!

Re: Problems deploying

Check out your development log again when using Firefox. Compare the parameters which are sent with that vs. Explorer. The nil.[] error sounds like some parameter isn't getting sent that is being expected.

Can you post your view and controller code which is related to this problem? A stack trace would help too.

Railscasts - Free Ruby on Rails Screencasts

Re: Problems deploying

One part of this problem is solved thanks to: http://railsforum.com/viewtopic.php?pid=7594#p7594.

This is my search index page:

<title>Dashboard - Search </title>
<table cellpadding="1" cellspacing="1" style="border:1px solid black;">
<td>
<%= form_remote_tag(:url => {:controller =>"search", :action => :submit}) %>
<label for="search">MON</label> 
<%= text_field_tag (:mon, params[:mon]) %>
<br>
<label for="search">PM</label>
<%= collection_select(:pdemployee, :employeeid, @pd_employees, :employeeid, :long_name, options = {:prompt => "ALL..."}) %>
<br>
<label for="search">AE</label>
<%= collection_select(:aeemployee, :aeid, @ae_employees, :employeeid, :long_name, options = {:prompt => "ALL..."}) %>
</td>
<td>
<%= radio_button(:selection, :date, "custom") %>
<label for="date">From:</label><%= date_select (:date, :start, :start_year => 1996, :order => [:month, :day, :year]) %>
<br>
&nbsp; &nbsp;&nbsp; &nbsp;<label for="date">To:</label><%= date_select (:date, :end, :start_year => 1996, :order => [:month, :day, :year])%>
<br>
<%= radio_button(:selection, :date, "quick", :checked => true) %>
<label for="date">Quick Dates:</label><%= select(:quickdate, :date, [['Last 30 Days', '30'],
                                                                ['Last 14 Days', '14'],
                                                                ['Last 45 Days','45'],
                                                                ['Last 60 Days', '60']]) %>
</td>
<td>
<label for="sort">Sort By:</label><%= select(:sort, :sortid, [['MON', 'MON'],
                                                                ['Account Exec','AE'],
                                                                ['Project Mgr','PM'],
                                                                ['Order Name', 'OrderName'],
                                                                ['Client','Client'],
                                                                ['Drop Rate','DropRate']]) %>
<br>
<%= radio_button(:selection, :choice, "ASC",:checked=> true) %>Ascending
<%= radio_button(:selection, :choice, "DESC") %>Descending
</td>
<td>
<%=check_box("orders", "median", {}, "yes", "no")%>Median Time for Orders
<br>
<%=check_box("shipments", "median", {}, "yes", "no")%>Median Time for Shipments
</td>
<td>
<%= submit_tag "SEARCH" %>
</td>
<%= end_form_tag %>
</table>

<div id="update_div" style="background-color:#eee; border:1px solid black; empty-cells: show;">
</div>


Here is my search controller w/ only pertinent information:
# search_controller.rb
class SearchController < ApplicationController
  before_filter :load_employees
 
  def load_employees
     @pd_employees = Employee.find_by_sql "SELECT DISTINCT EMPLOYEEID, FIRSTNAME, LASTNAME FROM EMPLOYEE S, ORDERS O WHERE S.EMPLOYEEID = O.PDEMPLOYEEID ORDER BY LASTNAME"
     @ae_employees = Employee.find_by_sql "SELECT DISTINCT EMPLOYEEID, FIRSTNAME, LASTNAME FROM EMPLOYEE S, ORDERS O WHERE S.EMPLOYEEID = O.AEEMPLOYEEID ORDER BY LASTNAME"
  end

  def index
  end
 
  def submit
      if params[:selection][:date]=="quick" #this the line of the failure
          quickdate = params[:quickdate][:date]
          startdate = Date.today - quickdate.to_i
          enddate = Date.today
      else
          year = params[:date]['start(1i)'].to_i
          month = params[:date]['start(2i)'].to_i
          day = params[:date]['start(3i)'].to_i
         
          startdate = Date.new(year, month, day)
         
          year = params[:date]['end(1i)'].to_i
          month = params[:date]['end(2i)'].to_i
          day = params[:date]['end(3i)'].to_i
          enddate = Date.new(year, month, day)
      end
      sql = "SELECT   o.ordernumber MON        , " +
      #my whole sql query
      @results = Order.find_by_sql sql
  end
end


The failure nil.[] is happening at the "if params[:selection][:date]=="quick" " line.

This is the submit.rjs file that is used to render the results of the search:

# submit.rjs
page.replace_html :update_div, :partial => 'orders'

I looked at my log and ryanb is right that some parameters are not sent over. Here is my log file when run through IE and submit the search request:

Processing SearchController#submit (for 10.1.4.80 at 2006-12-08 13:26:53) [POST]
  Session ID: ad6ac81b33e012a9f154ed4dba4ec3ef
  Parameters: {"aeemployee"=>{"aeid"=>"100000"}, "commit"=>"SEARCH", "mon"=>"", "pdemployee"=>{"employeeid"=>"ALL..."}, "date"=>{"start(1i)"=>"2006", "start(2i)"=>"12", "start(3i)"=>"8", "end(1i)"=>"2006", "end(2i)"=>"12", "end(3i)"=>"8"}, "shipments"=>{"median"=>"no"}, "action"=>"submit", "orders"=>{"median"=>"no"}, "selection"=>{"date"=>"quick", "choice"=>"ASC"}, "controller"=>"search", "sort"=>{"sortid"=>"MON"}, "quickdate"=>{"date"=>"30"}}
  Employee Load (0.016000)   SELECT DISTINCT EMPLOYEEID, FIRSTNAME, LASTNAME FROM EMPLOYEE S, ORDERS O WHERE S.EMPLOYEEID = O.PDEMPLOYEEID ORDER BY LASTNAME
  Employee Load (0.015000)   SELECT DISTINCT EMPLOYEEID, FIRSTNAME, LASTNAME FROM EMPLOYEE S, ORDERS O WHERE S.EMPLOYEEID = O.AEEMPLOYEEID ORDER BY LASTNAME
  Order Load (0.000000)   SELECT o.ordernumber MON        , o.name ordername         , pd.lastname pm             , ae.lastname ae             , c.orgname client     , o.bEnableAutoClose autoclose    , TO_CHAR( ROUND( SUM( rc.nStarted )/DECODE( SUM( rc.nStarted + rc.nCompleted + rc.nCompleted2 + rc.nScreened ),0,1000,SUM( rc.nStarted + rc.nCompleted + rc.nCompleted2 + rc.nScreened ) ) * 100 ), '999' ) AS DropRate FROM orders o, quotacell qc, employee pd, employee ae, customer c, responsecount rc, quotafeeder qf WHERE o.OrderID = qc.OrderID AND qc.quotacellid = qf.quotacellid AND qf.quotafeederid = rc.quotafeederid AND o.pdemployeeid = pd.employeeid AND o.aeemployeeid = ae.employeeid AND o.customerid = c.customerid (+) AND o.ordernumber IS NOT NULL AND o.dateins BETWEEN TO_DATE('2006-11-08','YYYY-MM-DD') AND TO_DATE('2006-12-08','YYYY-MM-DD') AND ae.employeeid = 100000 GROUP BY o.ordernumber, o.name, pd.lastname, ae.lastname, c.orgname, o.bEnableAutoClose, NVL(o.bidincidencepct,0) ORDER BY MON ASC
Rendering search/submit
Rendered search/_orders (0.00000)
Completed in 0.18700 (5 reqs/sec) | Rendering: 0.01500 (8%) | DB: 0.03100 (16%) | 200 OK [http://xpjammer/dashboard/search/submit]

Here is my log file when run through Firefox
Processing SearchController#submit (for 10.1.4.80 at 2006-12-08 12:05:07) [POST]
  Session ID: 3ff83f46e90a02e181f7144b09b761b3
  Parameters: {"aeemployee"=>{"aeid"=>"100000"}, "mon"=>"", "pdemployee"=>{"ssiemployeeid"=>"ALL..."}, "action"=>"submit", "controller"=>"search"}
  Ssiemployee Load (0.016000)   SELECT DISTINCT SSIEMPLOYEEID, FIRSTNAME, LASTNAME FROM SSIEMPLOYEE S, ORDERS O WHERE S.SSIEMPLOYEEID = O.PDEMPLOYEEID ORDER BY LASTNAME
  Ssiemployee Load (0.016000)   SELECT DISTINCT SSIEMPLOYEEID, FIRSTNAME, LASTNAME FROM SSIEMPLOYEE S, ORDERS O WHERE S.SSIEMPLOYEEID = O.AEEMPLOYEEID ORDER BY LASTNAME


NoMethodError (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.[]):
    /app/controllers/search_controller.rb:13:in `submit'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in `perform_action_without_filters'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in `perform_action_without_benchmark'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'
    C:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in `perform_action'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `process_without_filters'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in `process_without_session_management_support'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in `process'
    C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in `dispatch'
    C:/web/apps/dashboard/public/dispatch.cgi:10


Rendering C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/templates/rescues/layout.rhtml (500 Internal Error)


As you can see from the Firefox log, not all parameters are sent back. Thank you for any help!

Re: Problems deploying

Are you submitting the form by hitting the enter key? Or are you clicking the submit button? I remember hearing something about the two being handled differently.

Also, are some form fields disabled when the form is submitted? I think some browsers don't send the disabled field's data.

Railscasts - Free Ruby on Rails Screencasts

Re: Problems deploying

I tried both (clicking submit and hitting enter) with the same result. No fields are disabled. Some fields are just selected by default, like a radio button.

My search criteria box is in a table (each "column" has a different set of criteria to choose from). It seems like the variables for criteria from the first "column" are sent back to the controller, but the variables in the other 3 columns of the search criteria are ignored.

Re: Problems deploying

Try placing the start/end form tags outside of the table. I think this is the problem. You may also want to add <tr></tr> tags.

Railscasts - Free Ruby on Rails Screencasts

Re: Problems deploying

Placing the start/end form tags outside the table did the trick! Thanks ryanb!