Reputation: 3048
I have some problems with partial rendering in Rails.
This is in my routes.rb:
namespace :blog do
resources :posts, only: [:index, :show] do
resources :comments, only: [:new, :create]
end
end
This is my Blog::PostsController:
def show
@post = Post.find(params[:id])
@comments = @post.comments
end
This is in /views/blog/posts/show.html.erb
<%= render @comments %>
The _comment.html.erb partial is in /views/blog/comments/
The error message is:
Missing partial blog/comments/comment with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/home/mar1221/ruby/my_site/app/views"
Upvotes: 1
Views: 228
Reputation: 20049
Generally you'd pass the name of the partial (sans the underscore) like:
<%= render 'comment' %>
Which will attempt to render the partial _comment.html.erb
from the view paths.
The partial can be in the same directory as the parent view, in the shared directory, or in any other directory that has been included in the view path.
Check out:
http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials for a more detailed explanation, and additional options you can use when rendering partials.
Upvotes: 1