Reputation: 495
I want to save Json data in my Rails PostgreSQL database.
In my migration file
class IbmSubscription < ActiveRecord::Migration
def up
create_table :ibm_subscriptions do |t|
t.json 'ibm_response'
t.references :user, index: true
t.timestamps
end
end
def down
drop_table :ibm_subscriptions
end
end
I am unable to save JSON data in ibm_response I tried this in rails console
2.1.5 :004 > a = JSON.parse(@uri.to_s)
=> {"type"=>"SUBSCRIPTION_ORDER", "marketplace"=>{"base_url"=>"https://acme.appdirect.com", "partner"=>"ACME"}, "flag"=>"STATELESS", "creator"=>{"email"=>"[email protected]", "first_name"=>"DummyCreatorFirst", "language"=>"fr", "last_name"=>"DummyCreatorLast", "open_id"=>"https://www.appdirect.com/openid/id/ec5d8eda-5cec-444d-9e30-125b6e4b67e2", "uuid"=>"ec5d8eda-5cec-444d-9e30-125b6e4b67e2"}, "payload"=>{"company"=>{"country"=>"CA", "email"=>"[email protected]", "name"=>"Example Company Name", "phone_number"=>"415-555-1212", "uuid"=>"d15bb36e-5fb5-11e0-8c3c-00262d2cda03", "website"=>"http://www.example.com"}, "configuration"=>{"entry"=>{"key"=>"domain", "value"=>"mydomain"}}, "order"=>{"edition_code"=>"BASIC", "pricing_duration"=>"MONTHLY", "item"=>[{"quantity"=>"10", "unit"=>"USER"}, {"quantity"=>"15", "unit"=>"MEGABYTE"}]}}, "return_url"=>"https://www.appdirect.com/finishprocure?token=dummyOrder", "@xmlns:atom"=>"http://www.w3.org/2005/Atom"}
2.1.5 :005 > a = IbmSubscription.create(ibm_response: @uri)
WARNING: Can't mass-assign protected attributes for IbmSubscription: ibm_response
(0.2ms) BEGIN
SQL (5.7ms) INSERT INTO "ibm_subscriptions" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id" [["created_at", Fri, 02 Oct 2015 17:30:13 UTC +00:00], ["updated_at", Fri, 02 Oct 2015 17:30:13 UTC +00:00]]
(93.9ms) COMMIT
=> #<IbmSubscription id: 1, ibm_response: nil, user_id: nil, created_at: "2015-10-02 17:30:13", updated_at: "2015-10-02 17:30:13">
Its creating ibm_response: nil.
Please help me. Thanks
Upvotes: 0
Views: 231
Reputation: 28
Can't mass-assign protected attributes for IbmSubscription
This line implies that you need to add :ibm_response
to attr_accessible in your IbmSubscription
model.
Upvotes: 1