【发布时间】:2015-07-28 02:11:47
【问题描述】:
我在rails中有这个:
default_scope { order('created_at DESC') }
scope :by_source_name, ->(source_name) { where('source_name = ?', source_name) if source_name }
scope :by_check_name, ->(check_name) { where('check_name = ?', check_name.upcase) if check_name }
scope :by_status, ->(status) { where('status = ?', status.upcase) if status }
end
def index
@alerts = Alert.by_source_name(params[:source_name])
.by_check_name(params[:check_name])
.by_status(params[:status])
render json: @alerts, each_serializer: AlertSerializer
end
如何转换成grails?
【问题讨论】:
-
到目前为止你做了什么?
-
嗯,不知道你能不能用闭包做到这一点?
-
但这是 grails 社区,我们将如何阅读您的 rails 查询?至少把它改成伪代码。
标签: ruby-on-rails grails chaining named-query