문제

I have a simple index.json.rabl file with the following content:

collection @calls

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

I also have a helper method which replaces the source value with a company name:

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

Is it possible to replace the :source attribute in the RABL file with the helper method?

도움이 되었습니까?

해결책

You can do that using node:

collection @calls
attributes :time, :destination, :duration
node(:source) { |call| format_destination(call.source) }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top