New to AngularJS here and have some trouble getting $resource to work. I've created a factory and hardcoded the $resource object with what my backend needs in order to create a new plumber.
However, when I call the function, instead of passing only the params that I've entered, it creates a 'sort of' duplicate content in the form of a registration hash, as shown in hte backend of my app (bolded below). It's basically an exact duplicate of my params. Where did it come from???
The create() function is called by a button in the plumbers/new.html template
<button data-ng-click="create()">create</button>
Where did that hash come from???
new.js
angular.module('ngappApp')
.controller('PlumbersNewCtrl', function ($scope, $window, $resource, Plumbers) {
$scope.create = function(){
var test1 = new Plumbers({
"business[email]": "superhero@super.com",
"business[password]": "123123",
"business[name]": "alice cullen",
"business[company]": "alice pty ltd",
"business[abn]": "12312312",
"business[contact_number]": "0421772800",
"business[address]": "118 glass street",
"business[suburb]": "essendon",
"business[postcode]": "3040",
"business[employees_number]": "8"
});
test1.$save();
};
});
angular.module('ngappApp')
.factory('Plumbers', function($resource){
return $resource('/businesses');
});
And the response from the backend:
Started POST "/businesses" for 127.0.0.1 at 2013-08-26 20:40:27 +1000 Processing by Businesses::RegistrationsController#create as JSON Parameters: {"business[email]"=>"superhero@super.com", "business[password]"=>"[FILTERED]", "business[name]"=>"alice cullen", "business[company]"=>"alice pty ltd", "business[abn]"=>"12312312", "business[contact_number]"=>"0421772800", "business[address]"=>"118 glass street", "business[suburb]"=>"essendon", "business[postcode]"=>"3040", "business[employees_number]"=>"8", "registration"=>{"business[email]"=>"superhero@super.com", "business[password]"=>"[FILTERED]", "business[name]"=>"alice cullen", "business[company]"=>"alice pty ltd", "business[abn]"=>"12312312", "business[contact_number]"=>"0421772800", "business[address]"=>"118 glass street", "business[suburb]"=>"essendon", "business[postcode]"=>"3040", "business[employees_number]"=>"8"}} WARNING: Can't verify CSRF token authenticity (0.1ms) begin transaction (0.0ms) rollback transaction Completed 400 Bad Request in 6ms (Views: 0.1ms | ActiveRecord: 0.2ms)
EDIT:
Logging test1 shows the correct params without the 'extra'
Resource {business[email]: "superhero@super.com", business[password]: "123123", business[name]: "alice cullen", business[company]: "alice pty ltd",
business[abn]: "12312312"
business[address]: "118 glass street"
business[company]: "alice pty ltd"
business[contact_number]: "0421772800"
business[email]: "superhero@super.com"
business[employees_number]: "8"
business[name]: "alice cullen"
business[password]: "123123"
business[postcode]: "3040"
business[suburb]: "essendon"