When doing a ng-resource post to my Rails 4 app, rails is not adding the correct params, indeed it is adding an unexpected param called 'base' in the post.
My service:
App.factory('Rule', ['$resource', function ($resource){
return $resource('/json/rules/:id', {id:'@id'}, {
create: {method: 'POST'},
update: {method: 'PUT'},
delete: {method: 'DELETE'}
});
}]);
Rails route:
namespace :json, defaults: {format: :json} do
resources :rules
end
Rails controller:
class Json::RulesController < ApplicationController
respond_to :json
def create
rule = Rule.new(rule_params)
ap rule
rule.save! if rule.valid?
respond_with :json, rule
end
def update
rule = Rule.find(params[:id])
rule.update(rule_params)
respond_with rule
end
def rule_params
params.require(:rule).permit(:business_id, :raw_value => [])
end
end
When I do a post in my app this way:
$scope.rule.$update(function (){
$location.path('/businesses/{0}'.format($stateParams['id']));
}, SharedMessage.addResponse).finally(function (){
$rootScope.busy = false;
});
The http post itself sends the following data:
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate
Accept-Language:en-US,en;q=0.8,pt-BR;q=0.6,pt;q=0.4
Connection:keep-alive
Content-Length:142
Content-Type:application/json;charset=UTF-8
Cookie:hsfirstvisit=http%3A%2F%2Flocalhost%3A3000%2F%23%2Ftimeline||1402593173474; XSRF-TOKEN=GGNL6suNkGkOUEiUsEPxFE92C0AfCeLsT46GMrAJtoA%3D; __hstc=181257784.ee9ff47c4f98b78ed4d99e2ae1ee5edf.1402593173476.1415037010146.1415207051885.75; __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-TOKEN:GGNL6suNkGkOUEiUsEPxFE92C0AfCeLsT46GMrAJtoA=
X-Requested-With:XMLHttpRequest
X-XSRF-TOKEN:GGNL6suNkGkOUEiUsEPxFE92C0AfCeLsT46GMrAJtoA=
Request Payload:{"raw_value":["from:me"], "business_id":"125", "volume":0}
The rails app, receives the following parameters:
Parameters: {"raw_value"=>["from:me"], "business_id"=>"125", "volume"=>0, "base"=>{"raw_value"=>["from:me"], "business_id"=>"125", "volume"=>0}}
the problem here relies in not receiving a object 'rule' in the params and this strange 'base' param.
Do you guys know what hits may be?