[英]Random in mysql2 for rails 4 app
I'm using @places = Place.all.limit(2).order("RANDOM()")
for my app in production server and it working ok, but with passenger it showing me an error ActionView::Template::Error (Mysql2::Error: FUNCTION daysandnights.RANDOM does not exist: SELECT
places .* FROM
places ORDER BY RANDOM() LIMIT 2):
. 我在生产服务器中为我的应用程序使用
@places = Place.all.limit(2).order("RANDOM()")
,它运行正常,但在乘客ActionView::Template::Error (Mysql2::Error: FUNCTION daysandnights.RANDOM does not exist: SELECT
却向我显示错误ActionView::Template::Error (Mysql2::Error: FUNCTION daysandnights.RANDOM does not exist: SELECT
places .* FROM
places ORDER BY RANDOM() LIMIT 2):
ActionView::Template::Error (Mysql2::Error: FUNCTION daysandnights.RANDOM does not exist: SELECT
How can i fix this issue? 我该如何解决这个问题? Thanks in advance
提前致谢
@gotva, your answer can work. @gotva,您的答案可以奏效。
Specifically, when production I use rand(), when development I use random(). 具体来说,当生产时,我使用rand();当开发时,我使用random()。
if Rails.env.production?
scope :random8, -> { limit(8).order("RAND()") }
elsif Rails.env.development?
scope :random8, -> { limit(8).order("RANDOM()") }
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.