Application Controller Errors

Hello, I am just curious as to why I can't put the following code in the application controller:

if session[:date2use] else   @get_latestbill = Prov.connection.select_all("   SELECT     prov_bills.bill_cycle_date AS cd   FROM prov_bills   ORDER BY bill_cycle_date DESC   LIMIT 1")   @latestbill = @get_latestbill.to_s.slice(2,10)   session[:date2use] = @latestbill end

It gives me a "500 Internal Server Error Content-Type: text/html" error. However, when I use it within actions in my other controllers, it works perfectly. It would be very helpful in my app if I can use this in my Application Controller...

Any ideas?

Thanks, - Jeff Miller

Is this inside a method at all? or just in the class?

I'm not sure about ruby, but in most Oo languages you can only put declarations in a class. You can't put in code like that... you'd put that in an initialize method or something.

Could you maybe clarify where/how you're using the code?

Also, why are you using the connection directly? That code looks like it could be re-written as an active record find statement really easily:

unless session[:date2use]   session[:date2use] = Prov.find(:all, :order => "bill_cycle_date").first.bill_cycle_date.slice(2,10) end

=> this code might not be error free, i just typed it here...