Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 使用Angular和Rails:Bcrypt在尝试创建用户时引发错误_Angularjs_Ruby On Rails 4 - Fatal编程技术网

Angularjs 使用Angular和Rails:Bcrypt在尝试创建用户时引发错误

Angularjs 使用Angular和Rails:Bcrypt在尝试创建用户时引发错误,angularjs,ruby-on-rails-4,Angularjs,Ruby On Rails 4,我正在开发使用Angular和Rails的应用程序。我正在尝试创建新用户,但不断出现以下错误: BCrypt::Errors::InvalidHash (invalid hash): app/models/user.rb:14:in `new' app/models/user.rb:14:in `password' app/controllers/users_controller.rb:8:in `create' 看起来Angular正在创建密码,但它并没有传递给Rails Parame

我正在开发使用Angular和Rails的应用程序。我正在尝试创建新用户,但不断出现以下错误:

BCrypt::Errors::InvalidHash (invalid hash):
 app/models/user.rb:14:in `new'
 app/models/user.rb:14:in `password'
 app/controllers/users_controller.rb:8:in `create'
看起来Angular正在创建密码,但它并没有传递给Rails

Parameters: {"first_name"=>"John", "last_name"=>"Smith", "email"=>"john.smith@gmail.com", "username"=>"johnsmith", "password"=>"[FILTERED]", "user"=>{"first_name"=>"John", "last_name"=>"Smith", "username"=>"johnsmith", "email"=>"john.smith@gmail.com"}}
以下是我的前端代码:

app.js

$scope.signUp=function(){
var newUser={first_name:$scope.firstName,last_name:$scope.lastName,email:$scope.email,username:$scope.username,password:$scope.password}
$http.post('http://localhost:3000/users,新用户)
.成功(功能(数据){
控制台日志(数据);
if(data.errors){
console.log(data.errors);
}
否则{
$location.path(“/sign_in”);
}
})

};我能够摆脱这个错误。显然,Rails不喜欢传入的数据格式。在第2行的app.js文件中(参见问题),我替换了:

{first_name: $scope.firstName, last_name: $scope.lastName, email: $scope.email, username: $scope.username, password: $scope.password}'


你的解决方案完全有效。另一种方法是删除
users\u controller
user\u params
方法中的名称间距:

def user_params
  params.permit(:first_name, :last_name, :username, :email, :password)
end
而不是

def user_params
  params.require(:user).permit(:first_name, :last_name, :username, :email, :password)
end
def user_params
  params.require(:user).permit(:first_name, :last_name, :username, :email, :password)
end