How can I pass a nested json object to rails from angular -
i have this:
$scope.create = function() { var theproperty = { businessname: this.businessname, streetaddress: this.streetaddress, city: this.city, state: this.state, zip: this.zip, mdu: this.mdu, units: this.units, content: this.content }; var propertywrap = { property: theproperty }
i sent factory passes on rails. right now, def create has this:
@property = property.new(params[:property])
and have if/else/end in case far. but, until can far, haven't worked on safe_params or yet. first things first, right?
the object get's passed looks this:
{"property":{"businessname":"test","streetaddress":"test thgis","city":"asdfqw4r","state":"qfa","zip":"asdfas","units":"asdfa","content":"asdfasdf"}}
and console log shows this:
started post "/properties" 127.0.0.1 @ 2014-06-27 13:02:25 -0600 processing propertiescontroller#create html parameters: {"property"=>{"businessname"=>"test firefox", "streetaddress"=>"12 st", "city"=>"clearfield", "state"=>"ut", "zip"=>"55445", "units"=>"adf", "content"=>"asdfasdfasdf"}} completed 500 internal server error in 1ms
but i'm getting response back: activemodel::forbiddenattributeserror
i tried forming object pass way:
var propertywrap = { property : { businessname: this.businessname, streetaddress: this.streetaddress, city: this.city, state: this.state, zip: this.zip, mdu: this.mdu, units: this.units, content: this.content } }
but still got same error back.
activemodel::forbiddenattributeserror @ /properties ==================================================== > activemodel::forbiddenattributeserror
am doing crazy? should doing?
based on answer below, changed params , table use underscore instead of camelcase. so, i'm passing:
{"property":{"business_name":"something her","street_address":"960 s 550 e","city":"sometown","state":"te","zip":"85121","units":"adf","content":"asdfasdf asdfasdf"}}
i'm still getting same error, though.
probably reason of issue camelcase of params businessname , streetaddress. on rails side properties should business_name , street_address.
you can use https://github.com/finelineprototyping/angularjs-rails-resource "by default convert attribute names between underscore , camel case."
Comments
Post a Comment