Ruby on rails rails呈现json添加自定义属性

Ruby on rails rails呈现json添加自定义属性,ruby-on-rails,json,ruby-on-rails-4,Ruby On Rails,Json,Ruby On Rails 4,我有一个方法调用: def group render :json => Group.find(params[:id]) end 这使得: { id: 1, name: "Name Here", description: "Description Here", created_at: "2014-11-24T19:10:53.609Z", updated_at: "2014-11-24T19:10:53.609Z" } 我还想为正在渲染的组模型附加一个自定义属

我有一个方法调用:

def group
    render :json => Group.find(params[:id])
end
这使得:

{
  id: 1,
  name: "Name Here",
  description: "Description Here",
  created_at: "2014-11-24T19:10:53.609Z",
  updated_at: "2014-11-24T19:10:53.609Z"
}
我还想为正在渲染的组模型附加一个自定义属性。例如,我希望组JSON包含一个属性
消息:“Hello World”


我该怎么做?

在我的模型中添加一个名为
message
的方法,该方法返回一个字符串,然后调用

render :json => Group.find(params[:id]), :methods => :message 
成功了