按自己的 SQL 查询对 Rails 中的数据进行排序
Sorting data in Rails by own SQL query
我正在使用 gem Netzke 开发 Rails 应用程序。
我有来自 Netzke::Basepack 的 GridPanel 和我自己的按钮。我如何让他们通过我自己的 SQL 查询 过滤 GridPanel 的 table?
我试着像这样进行过滤:
def configure(c)
super
c.model = "Artist"
c.columns = [{ name: "name", filter_with: lambda{|rel, value, op| rel.where("name like ? ", "Scorpions") } }]
end
在特定列上添加 filter_with
可能不是您所需要的。尝试在网格上使用 scope
选项:
def configure(c)
super
c.model = "Artist"
c.scope = ->(rel) { rel.where("name like ?", "Scorpions") }
end
我正在使用 gem Netzke 开发 Rails 应用程序。 我有来自 Netzke::Basepack 的 GridPanel 和我自己的按钮。我如何让他们通过我自己的 SQL 查询 过滤 GridPanel 的 table? 我试着像这样进行过滤:
def configure(c)
super
c.model = "Artist"
c.columns = [{ name: "name", filter_with: lambda{|rel, value, op| rel.where("name like ? ", "Scorpions") } }]
end
在特定列上添加 filter_with
可能不是您所需要的。尝试在网格上使用 scope
选项:
def configure(c)
super
c.model = "Artist"
c.scope = ->(rel) { rel.where("name like ?", "Scorpions") }
end