Moved Activerecord out of views and into controller