[英]uninitialized constant User::Post (NameError)
我有以下問題,在UserController#show中必須有一個帖子列表,但是它會拋出一個錯誤,如屏幕截圖所示:
代碼中負責顯示用戶帖子的部分(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
您的幫助,在此先感謝,非常重要。
請原諒可能出現的錯誤
您應該以單數形式命名模型:
class Post < ActiveRecord::Base
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.