Reputation: 3
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:
The part of the code which is responsible to show user posts (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
part of a code in 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
Upvotes: 0
Views: 1321
Reputation: 51171
You should name your model in singular form:
class Post < ActiveRecord::Base
Upvotes: 4