How to append data to json in ruby/rails 5
If you use scaffold, e.g.:
rails generate scaffold MyItem
in the view folder you will see next files:
app/view/my_item/_my_item.json.jbuilder
app/view/my_item/index.json.jbuilder
so, you can add custom data to json output for an item, just add this:
json.extract! my_item, :id, :some_filed, :created_at, :updated_at
json.url my_item_url(my_item, format: :json)
json.my_data my_function(my_item)
As you can see, it's possible to modify as one item json output, as index json output.