首页 文章

第11章Micheal Hartl错误

提问于
浏览
-2

我在Michael Hartl的书上做了Sample App,在第11章中有一些错误

显示/home/andrey/RoR/sample_app/app/views/shared/_stats.html.erb,其中第5行引发:

未知的验证者:'PresenseValidator'

提取的来源(第5行):

5 <%= @ user.followed_users.count%>

模板包含跟踪:app / views / static_pages / home.html.erb

Rails.root:/ home / andrey / RoR / sample_app应用程序跟踪|框架跟踪|完整追踪

app / models / relationship.rb:4:在 <class:Relationship>' app/models/relationship.rb:1:in 'app / views / shared / _stats.html.erb:5:in _app_views_shared__stats_html_erb__765092261__621887978' app/views/static_pages/home.html.erb:8:in _app_views_static_pages_home_html_erb__496074363__614039518'

user.rb

class User <ActiveRecord :: Base has_many:microposts,dependent :: destroy has_many:relationships,foreign_key:“follower_id”,dependent :: destroy has_many:follows_users,through :: relationship,source ::: follow has_many:reverse_relationships,foreign_key:“followed_id “,class_name:”Relationships“,依赖:: destroy has_many:followers,through :: reverse_relationships,source :: follower

before_save before_create:create_remember_token

验证:name,presence:true,length:{maximum:50}

VALID_EMAIL_REGEX = / \ A [\ w - . ] @ [a-z \ d-]( . [a-z])* . [a-z] \ z / i

验证:电子邮件,在线状态:true,格式:{with:VALID_EMAIL_REGEX},唯一性:{case_sensitive:false}

has_secure_password

验证:密码,长度:{minimum:6}

def User.new_remember_token SecureRandom.urlsafe_base64结束

def User.encrypt(token)Digest :: SHA1.hexdigest(token.to_s)结束

def feed Micropost.where(“user_id =?”,id)结束

def follow?(other_user)relationships.find_by(followed_id:other_user.id)结束

def follow!(other_user)relationships.create!(follow_id:other_user.id)结束

def unfollow!(other_user)relationships.find_by(followed_id:other_user.id).destroy!结束

私人的

def create_remember_token
  self.remember_token = User.encrypt(User.new_remember_token)
end

结束

stats.erb.html

<% @user ||= current_user %>
 <div class="stats">
 <a href="<%= following_user_path(@user) %>">
 <strong id="following" class="stat">
  <%= @user.followed_users.count %>
 </strong>
 following
 </a>
 <a href="<%= followers_user_path(@user) %>">
 <strong id="followers" class="stat">
  <%= @user.followers.count %>
 </strong>
 followers
 </a>
 </div>

relationship.rb

class Relationship <ActiveRecord :: Base belongs_to:follower,class_name:“User”belongs_to:follow,class_name:“User”validates:follower_id,presense:true validates:follows_id,presense:true end

1 回答

  • 4

    你的关系中有拼写错误.rb

    validates :follower_id, presense: true 
    validates :followed_id, presense: true
    

    应该

    validates :follower_id, presence: true
    validates :followed_id, presence: true
    

相关问题