0

RABL JSON フィードに取り組んでおり、特定のオブジェクトにリンクできるカスタム ルート ノードを作成したいと考えています。

オブジェクトを次のように宣言しています。

object @event

出力の冒頭は次のとおりです。

{
  - event: {
      id: 131,

「- event」と表示されているところから event_path(event) を使用して特定のオブジェクトにリンクできるようにしたいと思います。RABL でカスタム ルート ノードを作成する方法はありますか?

4

1 に答える 1

0

この投稿には、あなたの質問に対する答えがあると思います。以下のコードは、ブログ投稿から取得したものです。

# app/views/users/show.rabl
object @user

# Declare the properties to include
attributes :first_name, :last_name

# Alias 'age' to 'years_old'
attributes :age => :years_old

# Include a custom node with full_name for user
node :full_name do |user|
  [user.first_name, user.last_name].join(" ")
end

# Include a custom node related to if the user can drink
node :can_drink do |user|
  user.age >= 21
end
于 2012-12-31T05:13:43.427 に答える