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

ckl · October 08, 2016 · Last by ckl replied at February 05, 2017 · 2125 hits

在用 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 哈哈,谢谢啊,好久没上,新年快乐

You need to Sign in before reply, if you don't have an account, please Sign up first.