게시 할 때 JSON 데이터를 PostgreSQL에 저장하는 grape을 사용하여 API를 만들려고합니다. 나는 위의 JSON과 잘 작동이 sample, 다음있어포도 API가있는 복잡한 JSON을 PostgreSQL에 게시
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
:
{
"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
}
이 루비 코드는 다음과 같습니다 다음은 샘플 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"
}
}
가 본 데이터베이스 스키마입니다 : : 나는 같은 더 복잡한 JSON과 함께 작동하도록 코드를 수정하려면 어떻게
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
좀 더 복잡한 JSON을 사용하려고하면 어떻게됩니까? Ruby 또는 PostgreSQL의 모든 오류 메시지? – jgm
실제로 실제로 그 실 거예요 ... 내가 havent postgres.I 그 필드를 포함하는 데이터베이스 스키마를 그리는 방법을 모르겠다. 난 그냥 현재 데이터베이스 스키마를 업데이 트 – iJade