我正在处理一个RABL JSON提要,我想创建一个自定义的根节点,在这个节点中我可以链接到特定的对象。
我像这样声明了对象:
object @event以下是输出的开头:
{
  - event: {
      id: 131,我想拥有它,这样我就可以使用事件(Event_path)链接到特定的对象,在那里它显示为"- event“。有没有办法在RABL中创建自定义根节点?
发布于 2012-12-31 13:13:43
我认为这个post可能对你的问题有答案。下面的代码取自博客帖子。
# 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
endhttps://stackoverflow.com/questions/13091491
复制相似问题