本文介绍了Squeel评估字符串作为连接的关键路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我真正想做的:

Outage.joins{eval "unit.plant"}

我会有一个字符串,代表

但这里是我得到的一个错误:

But here's what I get as an error:

#<Class:0x639e328>: unknown class: Squeel::Nodes::Function

我试过:

Outage.joins{"unit.plant"}

但这不行...我失踪了什么?

But that does not work... what am I missing?

我在github页面上看不到任何文档:

I don't see any documentation on this on the github page: https://github.com/ernie/squeel/

感谢您的帮助!



更新:
我发现一个真正令人困惑的方法来解决这个问题:


Update:I've found a really confusing way to pull this off:

("unit.plant".split ".").map{ |x| x.to_sym }.reverse.inject{ |acc, x| { x => acc } }

这将输出:

{:unit=>:plant}

被传递到连接squeel函数。我确定有一个比建立嵌套符号更好的方法:(

This can be passed into the joins squeel function. I'm sure there has to be a better way than to construct nested symbols :(

推荐答案

Outage.joins{Squeel::Nodes::KeyPath.new("unit.plant".split("."))}

资料来源:

这篇关于Squeel评估字符串作为连接的关键路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 21:18