On user\'s page i have many microposts and i want to add comment form and comments to each micropost.
I have three models: User, Micropost, Comment.
Try passing in the current micropost to the comment partial
<%= render 'shared/comment_form', micropost: micropost %>
Then add the micropost to the comment form_for
call
<%= form_for([micropost, @comment]) do |f| %>
Make sure your routes are nested
# in routes.rb
resources :microposts do
resources :comments
end
Then build the comment off of the micropost in the CommentsController
def create
@micropost = Micropost.find(params[:micropost_id])
@comment = @micropost.comments.build(params[:comment])
...
end