我試圖建立一個認證系統爲我的應用Rails 3中 - 錯誤的參數數目(0 1)
註冊用戶填寫一個表格,然後提交的呼叫用戶#註冊
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「身份證」,「hashed_password」和「鹽」(加時間戳),這是空@user.password(params[:user][:password])
後的散列現在包含「hashed_password」和「鹽值'@ user.save返回
引發ArgumentError在UsersController#註冊
錯誤的參數數目(0 1)
堆棧跟蹤
Started POST "https://stackoverflow.com/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"=>"[email protected]", "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)
任何想法?
您可以添加錯誤的堆棧跟蹤嗎? –
我已將它添加到問題 – mreysset
您的密碼方法沒有=。不應該是'def password =(pass)'? – HungryCoder