Rails 在 rails api 里看到这样的代码 求问

themorecolor · 2013年10月22日 · 最后由 TREE 回复于 2013年10月22日 · 2430 次阅读

belongs_to :valid_coupon, ->(o) { where "discounts > #{o.payments_count}" }

->(o) 这个 是什么意思 固定写法?

这表示 belongs_to 可以用这个 来加 限制条件?

这是从 1.9 开始引入的创建 lambda 的语法

匿名 #4 2013年10月22日
->(o) { where "discounts > #{o.payments_count}" }

等效于

lambda { |o| where "discounts > #{o.payments_count}" }
需要 登录 后方可回复, 如果你还没有账号请 注册新账号