2

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 that to the factory which passes it on to rails. Right now, def create just has this:

@property = Property.new(params[:property])

and then i have an if/else/end in case i get that far. But, until I can actually get it that far, I haven't worked on safe_params or anything yet. First things first, right?

The object that get's passed looks like 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" for 127.0.0.1 at 2014-06-27 13:02:25 -0600
Processing by PropertiesController#create as HTML
Parameters: {"property"=>{"businessName"=>"test from firefox", "streetAddress"=>"12 any st", "city"=>"clearfield", "state"=>"ut", "zip"=>"55445", "units"=>"adf",    "content"=>"asdfasdfasdf"}}
Completed 500 Internal Server Error in 1ms

But i'm getting a response back: ActiveModel::ForbiddenAttributesError

I even tried forming my object to pass this 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 I still got the same error back.

ActiveModel::ForbiddenAttributesError at /properties
====================================================

> ActiveModel::ForbiddenAttributesError

Am I doing this completely crazy? What should I be doing?

Based on an answer below, I changed the params and the table to use underscore instead of camelcase. So, now 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 the same error, though.

3
  • This is either strong parameters in controller, or for older rails versions unpermitted attributes in model Commented Jun 27, 2014 at 21:15
  • I'm using rails 4. How can I see if strong parameters are the issue? Commented Jun 27, 2014 at 21:16
  • Can you paste create method from controller and the model? Commented Jun 27, 2014 at 22:23

1 Answer 1

1

Probably the reason of issue is camelcase of params like businessName and streetAddress. On rails side this properties should be business_name and street_address.

You can use https://github.com/FineLinePrototyping/angularjs-rails-resource "By default we convert attribute names between underscore and camel case."

Sign up to request clarification or add additional context in comments.

5 Comments

Ok, I changed the params that are getting posted to use underscores, I also updated the table to match that. so, now 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"}} Still getting the same error.
Maybe you forgot about strong params in your controller, check this stackoverflow.com/a/17335871/905697 You should have something like this: ``` @property = Property.new(property_params) def property_params params.require(:property).permit(:business_name, :street_address) # add here rest end ```
Do I have to have that? I thought it was optional? See in my ruby controller I may have it looking for the peppery params and I'm not using strong params.
Strong params are enabled by default for rails 4 app. You need to permit params before passing them to Propery constructor. Check github.com/rails/strong_parameters
guess what? that was it. I didn't realize that I HAD to set strong params. I thought it was optional. Once I did that it was perfect. I changed my action for new to create, set a private method for the params and I was golden. you can see my updated controller here: github.com/jshultz/rails-omniauth/blob/master/app/controllers/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.