> On Jun 23, 2017, at 4:06 AM, fugee ohu <[email protected]> wrote:
> 
> 
> 
> On Saturday, June 17, 2017 at 9:32:55 PM UTC-4, Walter Lee Davis wrote:
> 
> > On Jun 17, 2017, at 11:31 AM, fugee ohu <[email protected]> wrote: 
> > 
> > I previously had it working and when you clicked a comment link a new page 
> > with a form would load 
> > 
> > 
> 
> If you have the form appearing on a new page now, and the form works and can 
> submit and save a comment, then you can change the link to the comment form 
> to include remote: true. Then create a new.js.erb file in the same views 
> folder as your current new.html.erb file. 
> 
> Use Gist or another pastbin to show me what your _form.html.erb looks like, 
> and what your index.html.erb (specifically your content_tag_for helper) looks 
> like at the moment. That will determine what we put into the new.js.erb file. 
> 
> Walter
> 
>  I can't figure out what variables from _post.html.erb will be available to 
> _comment.html.erb Also, do I need the index action in the 
> comments_controller.rb and an index view Maybe I need it to chain the two 
> partials together Here they are 
> https://gist.github.com/mices/d9aa8b344c214c4a422ffc8a538eb566

There's a few fundamental flaws here. You have the link to create a new comment 
inside the comment partial, not the post partial. The post needs to be the 
holder of this link, because there is only supposed to be one link per post 
that reads "Add a comment". Also, your link_to is missing the first argument -- 
there's no link text being supplied -- so I'm surprised if this template even 
compiles and displays. 

You're also missing the surrounding HTML that I suggested to you when you asked 
how to get this into the "Ajax" format. Without those surrounding 
content_tag_for wrappers, the return from Rails has no idea where to insert the 
form or the updated comments. What I believe you need to end up with is 
something that looks like this (in _post.html.erb):

content_tag_for :div, post, 'comments' do

  content_tag_for :div, post, 'comment_form_holder' do
    link_to 'Add a Comment', new_comment_path(commentable_id: post.id, 
commentable_type: 'Post'), remote: true
  end

  render 'comments/comment', collection: post.comments

end

So what you should get is a structure like this:

<div id="post_comments_123">
  <div id="post_comment_form_holder_123">
    <a href="/comments/new?commentable_id=123&commentable_type=Post" 
data-remote="true">Add a Comment</a>
  </div>
  <div id="post_comment_345">
    Hello, this is a comment
  </div>
</div>

When someone clicks the Add a Comment link, because it is set to remote: true, 
the comments/new.js.erb template will render (by default), and as we discussed 
earlier, that template is set to update the appropriate container 
(post_comment_form_holder_123) with the new comment form contents. So the 
action is you click the link, and the link disappears, replaced by the form to 
add a comment. 

Walter

> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/54955443-ff5b-42cd-9931-f70ba9c073f3%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/DBC87105-4F49-4650-9187-7BF7FA957CDE%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to