I’m Maximiliano Guzenski from Brazil and I am programing on ruby on rails only a couple of months.
I read a lot of books and articles about it but I could not clarify some doubts about design patterns:
Is it really good put some sql command on controller? because all articles that I see use sql into controllers, like:
@categories = Category.find :all, :conditions => ["date <= ? ", Date.today] :order => “name”
Or Should I create methods on model?
@categories = Category.find_all_before_date
@#my model (date = Date.today)
find :all, :conditions => ["date <= ? ", date] :order => “name”
In my app I have some reports, like that:
sql = <<EOF
select categories.id, categories.name
, sum(ledgers.value), sum(budgets.value)
from categories, ledgers, budgets
where categories.id = ledgers.category_id
categories.id = budgets.category_id
group by categories.id, categories.name
So, Where should I put this sql? model or controller ?
and How sould I execute it? using Category model?
or Is there way to use a generic model ?, some like that