未初始化的常量User :: Post(NameError)

时间:2015-01-08 10:37:45

标签: ruby-on-rails ruby ruby-on-rails-4

我有以下问题,在UserController #show中必须有一个帖子列表,但它会抛出错误,如屏幕截图所示:screenshot page of the user

负责显示用户帖子的代码部分(show.html.erb)

<div class="span8">
<% if @user.posts.any? %>
  <h3>Работы (<%= @user.posts.count %>)</h3>
  <ol class="posts">
    <%= render @posts %>
  </ol>
  <%= will_paginate @posts %>
<% end %>
</div>

posts.rb:

class Posts < ActiveRecord::Base
belongs_to :user
default_scope -> { order('created_at DESC') }
validates  :description, presence: true, lenght: { minimum: 6 }
validates  :user_id, presence: true
end

user.rb中的部分代码

class User < ActiveRecord::Base
has_many :posts, dependent: :destroy

你的帮助,提前谢谢非常重要。

文本中可能出现的错误的借口

1 个答案:

答案 0 :(得分:4)

您应该以单数形式命名您的模型:

class Post < ActiveRecord::Base