Rails Grape::Entity 中 using: APIEntities 可以加 option 参数吗?

ckl · 2016年10月08日 · 最后由 ckl 回复于 2017年02月05日 · 2125 次阅读

在用 Grape::Entity 时碰到穿参数问题,我想在用 using 的时候传参的时候添加参数,不仅仅是 expose 的数据 (例如:下面的 option[:is_join])

class ActivityInfo  <Grape::Entity
    expose :start_time do |records,options|
      records.start_time.strftime("%Y-%m-%d"" %H:%M")
    end
    expose :is_join do |records,options|
        option[:is_join]
    end
  ...
end
expose :data, using: APIEntities::ActivityInfo do |records, options|
      options[:records]
end

谢谢

你可以用

expose :data do |records, options|
  APIEntities::ActivityInfo.represent records,  options
end

#1 楼 @galeno 哈哈,谢谢啊,好久没上,新年快乐

需要 登录 后方可回复, 如果你还没有账号请 注册新账号