简体   繁体   English

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

[英]uninitialized constant User::Post (NameError)

I have the following problem, In UserController#show there has to be a list of posts, but it throws an error as shown in the screen shot: 我有以下问题,在UserController#show中必须有一个帖子列表,但是它会抛出一个错误,如屏幕截图所示: 用户的屏幕截图页面

The part of the code which is responsible to show user posts (show.html.erb) 代码中负责显示用户帖子的部分(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: 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

part of a code in user.rb user.rb中代码的一部分

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

Your help, thanks in advance is very important. 您的帮助,在此先感谢,非常重要。

Excuse for possible mistakes in the text 请原谅可能出现的错误

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

class Post < ActiveRecord::Base

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM