I'm sure there's an easy solution for this but I'm new to Rails and need help with syntax.
In my controller I have:
@products = Product.all
format.json { render :json => @products }
And it works fine, returning data with the default column names used in the DB:
"product": {
"created_at": "2010-10-08T17:24:27Z",
"id": 24,
"product_date": "2010-08-08",
"product_name": "Product One",
"updated_at": "2010-10-08T17:36:00Z"
}
What I need is something like:
"product": {
"created_at": "2010-10-08T17:24:27Z",
"id": 24,
"start": "2010-08-08",
"title": "Product One",
"updated_at": "2010-10-08T17:36:00Z"
}
That is, changing product_date to start and product_name to title, but only in the JSON output.
It seems like an easy problem to solve but I'm not sure how to express it in Ruby/Rails syntax, so I would really appreciate any help. I cannot rename the database columns.