开发者

How to get time from database in Rails?

How do you execute a SQL statement from Rails 3?

For example, the SQL statement "SELECT CURRENT_TIME" gets the ti开发者_如何学运维me (working in PostgreSQL).

Model.find_by_sql("SELECT CURRENT_DATE") returns a model object.


If you want to do what you are asking you can get a handle to the connection and just execute sql on it.

sql = "SELECT CURRENT_TIME"
ActiveRecord::Base.connection.select_value(sql)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜