How to save model with nested attributes with postman using JSON in a rails-api only app -
i creating rails-api app. have 2 models user , account. user model looks this.
class user < activerecord::base has_many :accounts accepts_nested_attributes_for :accounts end
and accounts model looks this,
class account < activerecord::base belongs_to :user end
on user create need save values account model well. need know how using postman. format in send data user gets created , value inserted in accounts model.
i using postman this.
the error geeting in server log below
started post "/auth?email=email000@meail.com&password=[filtered]&password_confirmation=[filtered]&account[school_name]=mjdhs" 127.0.0.1 @ 2015-10-01 12:54:56 +0530 activerecord::schemamigration load (0.2ms) select `schema_migrations`.* `schema_migrations` processing devisetokenauth::registrationscontroller#create */* parameters: {"email"=>"email000@meail.com", "password"=>"[filtered]", "password_confirmation"=>"[filtered]", "account"=>{"school_name"=>"mjdhs"}} unpermitted parameter: account unpermitted parameter: account unpermitted parameter: account
i'm not familiar with rails think may able out. agree connorcmkee helpful see controller code. in general json should like:
{ userproperty1: userpropertvalue1, userproperty2: userpropertvalue2, accounts: [ { accountsproperty1: accountspropertvalue1, accountsproperty2: accountspropertvalue2 } ]}
the above has whatever user properties user class has including accounts array of account object in turn should hold account property value pairs. hope helps. if need more doing request let me know.
Comments
Post a Comment