Я пытаюсь создать API, используя grape, который сохраняет данные JSON в PostgreSQL, когда опубликовано. Вот пример 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": "[email protected]",
"first_name": "David",
"google_plus": "http://google.com",
"id": 1
}
Это код Руби:
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
Я следую этому примеру, который отлично работает с приведенным выше JSON.
Как изменить код, чтобы он работал с более сложным 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": "[email protected]",
"first_name": "David",
"google_plus": "http://google.com",
"id": 1,
"chall": [{
"attributes": {
"type": "tegory__c",
"url": "/services0/sobjects/__c/a08Z0000000RmoTIAS"
}
}
Вот текущая схема базы данных:
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