2011-11-21 60 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