I'm trying to create an API using grape, which saves the JSON data to PostgreSQL when posted. Here is the sample JSON:
{
"about": "this is about me",
"company_name": "David Co",
"company_url": "http://google.com",
"created_at": "2013-02-03T13:09:37+05:30",
"email": "jones@david.com",
"first_name": "David",
"google_plus": "http://google.com",
"id": 1
}
This is the Ruby code:
class Posts < Grape::API
version 'v1', :using => :path
format :json
resource 'posts' do
get "/" do
Post.all
end
get "/:id" do
Post.find(params['id'])
end
post "/create" do
Post.create(params['post'])
end
end
end
I'm following this sample, which works fine with the above JSON.
How do I modify the code to make it work with a more complex JSON like:
{
"about": "this is about me",
"company_name": "David Co",
"company_url": "http://google.com",
"created_at": "2013-02-03T13:09:37+05:30",
"email": "jones@david.com",
"first_name": "David",
"google_plus": "http://google.com",
"id": 1,
"chall": [{
"attributes": {
"type": "tegory__c",
"url": "/services0/sobjects/__c/a08Z0000000RmoTIAS"
}
}
Here is the present database schema:
create_table :posts do |t|
t.string :first_name
t.string :email
t.string :company_name
t.string :google_plus
t.string :about
t.string :company_url
t.timestamps
end