Rails - Why are my comments not rendering? -
for application, listing projects related user on user's page. each project listed, want render comments made each project. able post comments each project database via form, unable render comments related comments. nothing renders. have been playing around users_controller thinking there no success. how fix it?
i have created models , controllers users, projects, , comments. comments belong projects , projects belong users.
schema.rb
create_table "comments", :force => true |t| t.integer "user_id" t.integer "project_id" t.text "content" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end
user.rb
has_many :projects has_many :comments
project.rb
has_many :comments belongs_to :user
comment.rb
belongs_to :project
routes.rb
resources :users resources :projects resources :comments end resources: comments
view/users/_projects.html.erb
<%= render @projects %>
users_controller.rb
def comments @user = user.find(params[:id]) @projects = @user.projects.newest.page(params[:comments_page]).per_page(10) @project = project.new @comments = project.find(params[:id]).comments.newest.page(params[:comments_page]).per_page(2) end
view/projects/_project.html.erb
<%= project.content %> <%= render 'comments/form', project:project %> <%= render @comments %> <%= will_paginate @comments, :param_name => 'comments_page' %>
view/comments/_comment.html.erb
<%= comment.content %>
in project.html.erb file try using loop so:
<% project.comments.each |c| %> #do <% end %>
Comments
Post a Comment