我每个人,我在处理 ruby 中的异常时遇到了一些问题。我不明白为什么我的陈述不起作用。
错误:找不到 id=14 的用户我想重定向到登录页面。
def login_required
begin
if session[:user_id] == nil
redirect_to login_path, :notice => "You are not logged"
elsif User.find(session[:user_id])
return nil
end
rescue ActiveRecord::RecordNotFound
redirect_to login_path, :notice => "No user corresponding in database"
end
end
希望您能够帮助我。
亲切地,奥宾