ruby on rails - Render view from another view : controller not called -


i'm developing litte blog application , @ moment i'm facing problem can't resolve.

i have 2 models @ moment :
1. post
2. comment

i can manage posts without difficulties have problems comments. chose make relation has_many / belongs_to between post , comment models. i'd display comments related post when user on post's page. erb looks :

#some code #... #... #render comments <%= render :template => "comments/index", :locals => {:post_id => @post.id} %> 

my problem here method index commentscontroller never called. put puts in index method , never displayed in console.

should use tag render view ? there way ?

thanks in advance help.

if post view page show comments, don't have call comments/index comments, show comments when rendering post view, example

in post view

#some code #... # render comments <% @post.comments.each |c| %>   <%= c.content%>   # ... <% end %> 

or put them in partial post parameter if comments used in many views

in app/views/partials/_comments.html.erb

# render comments <% post.comments.each |c| %>   <%= c.content%>   # ... <% end %> 

and render partial want show comments:

#some code #... # render comments <%= render partial: "partials/comments", locals: { post: @post } %> 

using comments/index comments , showing them in view more frondend tech such javascript/ajax load page parts dynamically. in case, comments/index more api call(render json format instead of html view).


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -