# Application Controller Errors

**URL:** <https://discuss.rubyonrails.org/t/application-controller-errors/25956>\
**Category:** rubyonrails-talk\
**Created:** [March 7, 2008, 12:47am UTC](https://discuss.rubyonrails.org/t/application-controller-errors/25956 "2008-03-07T00:47:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [March 7, 2008, 12:47am UTC](https://discuss.rubyonrails.org/t/application-controller-errors/25956/1 "2008-03-07T00: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 &nbsp;&nbsp;@get\_latestbill = Prov.connection.select\_all(" &nbsp;&nbsp;SELECT &nbsp;&nbsp;&nbsp;&nbsp;prov\_bills.bill\_cycle\_date AS cd &nbsp;&nbsp;FROM prov\_bills &nbsp;&nbsp;ORDER BY bill\_cycle\_date DESC &nbsp;&nbsp;LIMIT 1") &nbsp;&nbsp;@latestbill = @get\_latestbill.to\_s.slice(2,10) &nbsp;&nbsp;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

---

<div class="post-metadata">

**Author:** ![Jonathan\_Fantham](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@Jonathan\_Fantham](https://discuss.rubyonrails.org/u/Jonathan_Fantham)\
**Post date:** [March 7, 2008, 2:30am UTC](https://discuss.rubyonrails.org/t/application-controller-errors/25956/2 "2008-03-07T02:30:16Z")

</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] &nbsp;&nbsp;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...
