我正在尝试为我的应用程序构建身份验证系统
注册用户填写表格,然后提交调用 user#signup
def signup
@user = User.new(params[:user])
@user.password(params[:user][:password])
@user.save
end`
我的用户模型包含
def password(pass)
@password=pass
self.salt = User.random_string(10)
self.hashed_password = User.encrypt(@password, self.salt)
end
尝试调试时,我检查了 @user 哈希中包含的内容:
在
@user = User.new(params[:user])
哈希包含我的参数 exept 'id'、'hashed_password' 和 'salt'(加上时间戳)之后,它们是空的哈希后
@user.password(params[:user][:password])
现在包含“hashed_password”和“salt”的值@user.save 返回
用户控制器中的参数错误#signup
参数数量错误(0 代表 1)
堆栈跟踪
Started POST "/users/signup" for 127.0.0.1 at Fri Oct 05 14:23:49 +1000 2012
Processing by UsersController#signup as HTML
Parameters: {"user"=>{"last_name"=>"last", "first_name"=>"first", "login"=>"myusername", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "email"=>"me@gmail.com", "dob(1i)"=>"1980", "dob(2i)"=>"4", "dob(3i)"=>"2"}, "authenticity_token"=>"R8/BNPox9F9rkUXZQ84xjnsplRjqLJYe35EtGjKEAWk=", "utf8"=>"✓", "commit"=>"Create User"}
(0.1ms) begin transaction
(0.0ms) rollback transaction
Completed 500 Internal Server Error in 10ms
ArgumentError (wrong number of arguments (0 for 1)):
app/controllers/users_controller.rb:17:in `signup'
app/controllers/users_controller.rb:16:in `signup'
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.1ms)
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.1ms)
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (7.8ms)
任何的想法?