10

I have a method call:

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

Which renders:

{
  id: 1,
  name: "Name Here",
  description: "Description Here",
  created_at: "2014-11-24T19:10:53.609Z",
  updated_at: "2014-11-24T19:10:53.609Z"
}

I would like to also append a custom attribute the the group model being rendered. For example I'd like the group JSON to include an attribute message : "Hello World"

How can I do this?

1 Answer 1

20

Adding a method to my model called message that returns a string and then calling,

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

did the trick.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.