gpt4 book ai didi

ruby-on-rails - 在 RABL 中使用 JSON 中的辅助方法?

转载 作者:行者123 更新时间:2023-12-02 00:01:46 25 4
gpt4 key购买 nike

我有一个包含以下内容的简单 index.json.rabl 文件:

collection @calls

attributes :time, :destination, :source, :duration

我还有一个辅助方法,可以用公司名称替换​​ source 值:

  def format_destination(destination_number)
case destination_number
when "12345
"Name One"
when "67891"
"Name Two"
else
destination_number
end
end

是否可以用辅助方法替换RABL文件中的:source属性?

最佳答案

你可以使用 node 来做到这一点:

collection @calls
attributes :time, :destination, :duration
node(:source) { |call| format_destination(call.source) }

关于ruby-on-rails - 在 RABL 中使用 JSON 中的辅助方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20939837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com