# Application Controller Errors

**URL:** <https://www.ruby-forum.com/t/application-controller-errors/131228>\
**Category:** Rails\
**Created:** [March 7, 2008, 1:47am UTC](https://www.ruby-forum.com/t/application-controller-errors/131228 "2008-03-07T01:47:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 7, 2008, 1:47am UTC](https://www.ruby-forum.com/t/application-controller-errors/131228/1 "2008-03-07T01:47:17Z")

</div>

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 M.

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 7, 2008, 3:31am UTC](https://www.ruby-forum.com/t/application-controller-errors/131228/2 "2008-03-07T03:31:15Z")

</div>

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…

On Mar 7, 1:47 pm, Jeff M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
