I'm trying to implement replies with comments and so when you click "reply" a partial should show up underneath the current comment.
So in my reply.js.erb, I have
$("<%= j render(:partial => 'reply', :locals => { :comment => Comment.build_from(@obj, current_user.id, "") }) %>").insertAfter($('<%= @div_id %>')).show('fast');
Where @div_id is the division id for the comment that it's replying to. So what's happening right now is that the partial will not display and it's also hiding the content underneath the @div_id. Not sure what's going on.
EDIT: So, I believe I figured out why it's being hidden. I have another javascript file in assets called comments.js.coffee which contains this -
jQuery ->
$(document)
.on "ajax:beforeSend", ".comment", ->
$(this).fadeTo('fast', 0.5)
.on "ajax:success", ".comment", ->
debugger;
$(this).hide('fast')
.on "ajax:error", ".comment", ->
debugger;
$(this).fadeTo('fast', 1)
".comment" is the header for the partial which contains the Reply link. That same partial contains a Destroy link. So somehow when I click Reply it's running this code as well which is hiding the comment afterwards. Here's my partial for comment
%div.comment{ :id => "comment-#{comment.id}" }
%hr
= link_to "×", comment_path(comment), :method => :delete, :remote => true, :confirm => "Are you sure you want to remove this comment?", :disable_with => "×", :class => 'close'
%h4
= comment.user.first_name
%small= comment.updated_at
%p= comment.body
%p= link_to "Reply", comment_reply_path(comment), :method => :get, :remote => true
How would I go about fixing this?
May be @div_id
is not having #
with it, so below code may work after prepending #
before @div_id
$("<%= j render(:partial => 'reply', :locals => { :comment => Comment.build_from(@obj, current_user.id, "") }) %>").insertAfter($('#<%= @div_id %>')).show('fast');
Can you try the following?
$('<%= @div_id %>').append("<%= j render(:partial => 'reply', :locals => { :comment => Comment.build_from(@obj, current_user.id, "") }) %>").show('fast');
can you try append
instead?
$("<%= j ( render partial: 'reply', :locals => { :comment => Comment.build_from(@obj, current_user.id, "") }) %>").insertAfter($('#<%= @div_id %>')).show('fast');
This will work correctly....just syntactical change
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With