I’m using Rails with ActiveAdmin gem. And I want to select some information from mysql database.
sql = ActiveRecord::Base.connection();
s="SELECT word FROM dics WHERE word LIKE 'tung%'";
ten = sql.execute(s);
But when I printed out “ten” to screen, it showed that:
#<Mysql2::Result:0x4936260>
How can I get the information of records?
I suggest that you don’t use
ActiveRecord::Base.connectiondirectly. Sticking with ARel syntax should work for most cases, and your example doesn’t seem like an edge case.As stated in the comments above, try the following:
In order to pluck some special field of object, not objects themselves, use
pluckinstead ofall: