2011-09-20 2 views
0

Devise를 사용해 보았습니다.하지만 나에게 적합하지 않았으므로 처음부터 인증 및 세션을 구축하기로 결정했습니다. 나는 그 문제가 고의가 아니라는 것을 알았지 만 그것은 mysql이다. 어떤 이유로 사용자를 등록하면 정보와 속성이 데이터베이스에 저장됩니다. 전자 메일 및 암호를 사용하여 로그인하면 잘못된 전자 메일/암호임을 계속 알려줍니다. 로그는 다음과 같습니다 RoR의 세션에서 mysql이 선택 이메일 NULL을 가져 오려고합니다.

Processing by SessionsController#create as HTML 
Parameters: {"utf8"=>"✓", "authenticity_token"=>"NFudGruZS79uwDrKzbHDQrBjlcwQ7AkC958vI4aHDAs=", "session"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}, "commit"=>"Sign in"} 
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`email` IS NULL LIMIT 1 

몇 가지 조사 후, 나는 새로운 응용 프로그램이 잘 작동하기 때문에 제대로 MySQL의 또는 다른 보석을 설치하지 않았기 때문에 그렇지 않은 것을 알고있다.

내가 입력 한 이메일을 가져 오지 않고 대신 이메일을 가져 오는 것이 왜 NULL인지 아는 사람이 있습니까?

새 데이터베이스를 만들고 대신 database.yml 파일을 새 데이터베이스로 전환해야합니까?

미리 감사드립니다.

편집 - 좀 더 CODE

사용자 모델 :

class User < ActiveRecord::Base 

attr_accessor :password 
attr_accessible :name, :email, :secondary_email, :password, :password_confirmation, :gender 

has_many :user_owner_relationships 
has_many :owners, :through => :user_owner_relationships 
has_many :cash_endowments 
has_many :checks, :through => :cash_endowments 
has_many :owners, :through => :cash_endowments 

email_regex = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i 


validates :email,     :presence => true, 
            :uniqueness => { :case_sensitive => false }, 
            :format => { :with => email_regex } 

validates :name,     :presence => true, 
            :length => { :maximum => 40 } 

validates :password,    :presence => true, 
            :confirmation => true, 
            :length => { :within => 6..20 } 

sessions_controller (사용자 컨트롤러가 표준)

def new 
@title = "Sign in" 
end 

def create 
    user = User.authenticate(params[:email], params[:password]) 
if user 
    session[:user_id] = user.id 
    redirect_to root_path, :notice => "Welcome '#{user.first_name}" 
else 
    flash.now.alert = "Invalid email or password." 
    render "new" 
end 
end 

답변

0

신인 실수 - 나의 새로운 때문에

그것은 사실입니다. 세션 컨트롤러에 대한 html.erb가 : 세션 기호를 가져 오지 않았습니다. 이 코드 :

<%= form_for (:session, :url => sessions_path) do |f| %> 

그래서 대신 form_tag를 사용했습니다.

관련 문제