Rails 4 add unexpected param in AngularJS resource post -


While posting an NG-resource on my Rail 4 app,

App.factory ('rule', ['$ resource', function ($ resource) {unexpected ultimate} returns $ resource ('/ json / Update: {method: 'PUT'}, delete: {method: DELETE}}}}}] ;

Railway route:

  Namespace: Jason, Default: {format :: json} Resource: Rule End  

Rail Controller:

  Class Jason :: Rule Controller & lt; ApplicationController response_to: json def create rule = rule.new (rule_params) AP rule rule.save! If rule.valid? respond_with: json, end def update rule rule = Rule.find (parameter [: id]) rule.update (rule_params) end respond_with rule def rule_params params.require (: Rules) .permit (: business_id ,: raw_value = & gt ; []] End End << / code> 

When I post one in my app like this:

  $ scope.rule. $ Update (function () {$ location) .path (. '/ businesses / {0} "format ($ stateParams [' id ']));}, SharedMessage.addResponse) .finally (function () {$ rootScope.busy = false; });  

The http post sends the following data:

  accept: application / json, text / plain, * / * Accept-Encoding: gzip, air Accept Removal-Language: en-US, N, Q = 0.8, pt-BR; Q = 0.6, pt; Q = 0.4 Connection: Survival Content-Length: 142 Material Type: Application / json; Charset = UTF-8 cookie: hsfirstvisit = http% 3A% 2F% 2Flocalhost% 3A3000% 2F% 23% 2Ftimeline || 1402593173474; XSRF-Token = GGNL6suNkGkOUEiUsEPxFE92C0AfCeLsT46GMrAJtoA% 3D; __hstk = L8l257784ki9ff47c4f98b78ed4d99e2aelee5edfkl402593l73476kl4l50370l0l46kl4l520705l885k75; __hssrc = 1; Hubspotutk = ee9ff47c4f98b78ed4d99e2ae1ee5edf; _myapp_session = Uk9LS - 914a262148c5784afe30087e8a5f6572fbf7d342 host: localhost: 3000 Origin: http: // localhost: 3000 Referer: http: // localhost: 3000 / User-Agent: Mozilla / 5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit / 537.36 ( KHTML, like Gecko) Chrome / 38.0.2125.111 Safari / 537.36 x CSRF- Tokens: GGNL6suNkGkOUEiUsEPxFE92C0AfCeLsT46GMrAJtoA = X-requested-with: XMLHttpRequest X XSRF- Tokens: GGNL6suNkGkOUEiUsEPxFE92C0AfCeLsT46GMrAJtoA = request payload: {the "Raw_value": [ ": I"] , "Business_ID": "125", "Volume": 0}  

Rail application receives the following parameters:

  Paramet R: {"raw_value" = & gt; ["From: me"], "business_id" => 
"125", "Quantity" = & gt; 0, "base" = & gt; {"Raw_value" = & gt; ["From: me"], "business_id" = & gt; "125", "Volume" = & gt; 0}}

Here the problem is dependent on not receiving the 'rules' in the parameter and this strange 'base' is the ultimate.

Do you know what can happen?

I do not know Angela RJS but try to answer me.

The problem here is not to get "an object" rule supreme and the odd 'base' ultimate

strange by The parameter is because you have enabled the wrap_parameters setting to check your config / initializer / wrap_parameters.rb . To disable it, you should just

  wrap_parameters false  

  request payload: {"raw_value": [from "I"], "Bijnes_aidi": "125", "volume": 0}  

and

params.require (: Rules ) .Permit (: business_id ,: raw_value => [])

This means that you are not sending parameters in the proper way. It must be written in the rules

  request payload: {"rule": {"raw_value": ["From: me"], "business_id": " 125 "," Volume ":}}  

Therefore, do not place your setting somewhere in the angular so that it returns the parameter Give the right way


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -