나는 official Authlogic tutorial을 따라 갔지만 어떤 것이 나타났습니다. 나는 그 전체 생각Authlogic 튜토리얼에 이어 : # <UserSession : {: unauthorized_record => "<protected>"}>에 대한 정의되지 않은 메소드`email '>
# user.rb
class User < ActiveRecord::Base
acts_as_authentic do |c|
c.crypto_provider = Authlogic::CryptoProviders::BCrypt
c.require_password_confirmation(false)
end
attr_accessible :username, :email, :password
end
# users_controller.rb
def show
@user = @current_user
end
# application_controller.rb
private
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session and current_user_session.user
end
:
나는 성공적으로 사용자를 생성,하지만 난 show
에 자신의 프로필 페이지를하려고 할 때, 나는 다음과 같은 오류 얻을 :
undefined method `email' for #<UserSession: {:unauthorized_record=>"<protected>"}>
여기에 관련 코드의를 체인. 그리고 여기에보기가 있습니다 :
# views/users/show.html.erb
<%=h @user.username%>
email: <%=h @user.email %>
<%= link_to "Edit", edit_account_path %>
"전자 메일"줄을 제거하면 "편집"링크 만있는 페이지가 나타납니다. 사용자 이름이 나타나지 않습니다. 그러나 <%= debug @user %>
을 추가하면 무슨 일이 일어나는지 정확히 알 수 있으며 데이터베이스에 저장된대로 email
및 username
의 값을 올바르게 인쇄합니다. @user.username
이 왜 인쇄되지 않는지 전혀 알지 못하며 @user.email
을 인쇄하려고 할 때 오류가 발생합니다.
show.html.erb
layout of the tutorial은 을 사용하며 작동합니다. 방금 "로그인"을 "사용자 이름"으로 변경했습니다.
undefined method `email' for #<UserSession: {:unauthorized_record=>"<protected>"}>
사용한 edit
레이아웃과 부분적인 형태이다 : 다시
# views/users/edit.html.erb
<h1>Edit My Account</h1>
<% form_for @user, :url => account_path do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :object => f %>
<%= f.submit "Update" %>
<% end %>
<br />
<%= link_to "My Profile", account_path %>
#views/users/_form.erb
<%= form.label :username %><br />
<%= form.text_field :username %><br />
<br />
<%= form.label :email %><br />
<%= form.text_field :email %><br />
<br />
<%= form.label :password, form.object.new_record? ? nil : "Change password" %><br />
<%= form.password_field :password %><br />
<br />
모두에서 그대로 촬영 나는 "편집"을 클릭하면
은 또한, 나는 같은 원래의 오류 튜토리얼, 그냥 작동합니다.
필자는 Rails 2.3.2와 최신 Authlogic (현재 설치된 버전이 무엇이든간에)을 실행하고 있으며 피곤하고 좌절 한 두뇌가 말할 수있는 한 데이터베이스에 필요한 모든 필드가 있으며 they are spelled correctly.
무슨 일 이니? CURRENT_USER 실제로 방법이 아닌 인스턴스 변수 @current_user 것을
# users_controller.rb
def show
@user = current_user
end
주의 사항 :
'current_user' 메소드는'@current_user'를 리턴합니다. 하지만 어쨌든 그것을 시도하고 아무것도 바뀌지 않았다. 하지만 고마워. –