2011-11-21 28 views
-3

我已經試過以下ROR代碼:試圖獲得認證的紅寶石在工作軌道

class SessionsController < ApplicationController 
    def new 
    end 

    def create 
    user = User.authenticated(params[:email], params[:password) 
    if user 
     session[:user_id] = user_id 
     flash[:notice] = "Log In Complete" 
     redirect_to root_url 
    else 
     flash.now.alert = "Invalid Email or Password" 
     render 'create' 
    end 
    end 

    def destroy 
    session[:user_id] = nil 
    redirect-to root_url, :notice =>"Logged Out" 
    end 
end 

但我得到這個錯誤:

I:/dev/abierto/app/controllers/sessions_controller.rb:5: syntax error, unexpected ')', expecting ']'
I:/dev/abierto/app/controllers/sessions_controller.rb:19: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '(' redirect-to root_url, :notice =>"Logged Out"
I:/dev/abierto/app/controllers/sessions_controller.rb:19: syntax error, unexpected tASSOC, expecting tCOLON2 or '[' or '.' redirect-to root_url, :notice =>"Logged Out"
I:/dev/abierto/app/controllers/sessions_controller.rb:22: syntax error, unexpected keyword_end, expecting $end

任何人可以幫助我,告訴我什麼,我我做錯了嗎?

+1

你讀過錯誤日誌嗎?你是否試圖理解它並改變它告訴你的錯誤? >>你的用戶'params'缺少聲明的結尾......只是**閱讀錯誤信息** – JMax

+0

看看'params [:password]' – Nick

回答

0

起初:

user = User.authenticated(params[:email], params[:password**]**) 

...但可能會有更多的錯誤。粘貼行號

2

你缺少]第5行,它應該閱讀:

user = User.authenticated(params[:email], params[:password]) 

redirect-to是錯誤的,它應該是redirect_to

我不是在flash.now.alert甚至不確定,也許應該是flash.now[:alert]

+0

感謝剛剛開始在web開發中大約一個星期前搞亂了,這些錯誤信息對於外行人來說相當隱蔽。 – Wolfmang1

+0

並感謝由於某種原因的不接受 – kain