how to append data to json in ruby/rails?
The to_json
method takes an option object as parameter . So what you can do is make a method in your item class called as message and have it return the text that you want as its value .
class Item < ActiveRecord::Base
def message
"it works"
end
end
render :json => item.to_json(:methods => :message)
item = Item.find(params[:id])
item["message"] = "it works"
render :json => item.to_json