English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I want to have a method in my controllers defined that returns the count of records in a users database. Is this the correct syntax? What am I doing wrong. I seem to get an error.

def users
@users = User.find(:all)
sql = ActiveRecord::Base.connection();
sql.execute "SET autocommit=0";
sql.begin_db_transaction
id, value =sql.execute("SELECT COUNT(*) as "Number of Users" FROM users;").fetch_row;
sql.commit_db_transaction
@count=value;
end

2007-12-10 05:41:08 · 1 answers · asked by theedge2343 2 in Computers & Internet Programming & Design

1 answers

Doesn't this do the trick for you:

@count = User.count

??

2007-12-10 05:49:43 · answer #1 · answered by Anonymous · 0 0

fedest.com, questions and answers