ich diesen Fehler nach dem Login schlagen meine volle Spur istnicht definierte Methode `[]‘ für nil: NilClass + nach dem Login
undefined method `[]' for nil:NilClass
Extracted source (around line #20):
def create
@session = Session.new(params[:session], request.remote_ip)
if @session.valid?
set_current_user(@session.current_user)
add_to_current_cart params
Application Trace | Framework Trace | Full Trace
app/models/session.rb:12:in `initialize'
app/controllers/sessions_controller.rb:20:in `new'
app/controllers/sessions_controller.rb:20:in `create'
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>==",
"email"=>{"{:placeholder=>\"[email protected]\",
:tabIndex=>\"1\",
\"class\"=>\"\"}"=>""},
"password"=>"[FILTERED]",
"commit"=>"Log In"}
Meine Sitzungen Controller-Datei ist
def create
@session = Session.new(params[:session], request.remote_ip)
if @session.valid?
set_current_user(@session.current_user)
add_to_current_cart params
add_to_favorites params
if session[:return_to]
redirect_to session[:return_to]
else
Session .rb Datei ist
class Session
INCORRECT_PASSWORD = "The password you entered is incorrect. Please try again (make sure your caps lock is off)."
EMAIL_NOT_FOUND = "The email id you entered does not belong to any account."
MANDATORY_FIELDS = "You must fill in all of the fields"
include ActiveModel::Validations
attr_accessor :email, :password, :errors
attr_reader :current_user
def initialize(params={}, ip_address=nil)
@errors = ActiveModel::Errors.new(self)
@email = params[:email]
@password = params[:password]
@current_user = User.find_by_email(@email)
@ip_address = ip_address
end
def valid?
mandatory_fields_presence
if @current_user && @errors.empty?
if @current_user.waiting_for_confirmation?
email_confirmation_link = "/account/#{@current_user.uuid}/send-confirmation-email"
@errors.add(:base, "Please confirm your account first. <a href='#{email_confirmation_link}'>Resend confirmation link</a>")
end
end
authenticate if @errors.empty?
@current_user.signed_in(@ip_address) if @errors.empty?
@errors.empty?
end
private
def mandatory_fields_presence
@errors.add(:email, MANDATORY_FIELDS) if @email.blank? or @password.blank?
end
def authenticate
@errors.add(:email, EMAIL_NOT_FOUND) if @current_user.nil?
if @errors.empty? && [email protected]_user.authenticated?(@password)
@errors.add(:password, INCORRECT_PASSWORD)
end
end
end
if session[:login_page] == true
redirect_to root_path
else
redirect_to :back
end
end
else
if session[:login_page] == true
render :new
else
flash[:login_failed] = OpenStruct.new({ :errors => @session.errors, :login_failed => true })
redirect_to :back
end
end
end
Arbeiten an Rubin 1.9.3, 4.2.5 Schienen ich bin unabl e, um sich einzuloggen, nachdem Sie auf den Login-Button geklickt haben, sogar das Anmeldeformular bekommt diese Art von Problem. Helfen Sie mir, dieses Problem zu beheben?
die Parameter, die Sie senden, enthält nicht den 'Session Hash' – Sravan
Sie senden die Parameter falsch, überprüfen Sie meine Antworten auf, wie Sie die Parameter senden können. Bitte fügen Sie das Formular ein – Sravan