adds hide/show behaviour to comment forms

This commit is contained in:
rgarcia
2015-07-25 18:49:00 +02:00
parent bd92f6ec5c
commit 3cec9b98f2
2 changed files with 20 additions and 7 deletions

View File

@@ -0,0 +1,9 @@
jQuery ->
toggle_comment = (id) ->
$("#js-comment-form-#{id}").toggle()
$('.js-add-comment-link').click ->
id = $(this).data().id
toggle_comment(id)
false

View File

@@ -1,7 +1,11 @@
<%= form_for [@debate, Comment.new] do |f| %> <%= link_to "Comentar", "", class: "js-add-comment-link", data: {'id': parent.id} %>
<div id="js-comment-form-<%= parent.id %>" style="display:none">
<%= form_for [@debate, Comment.new] do |f| %>
<%= f.text_area :body %> <%= f.text_area :body %>
<%= f.hidden_field :commentable_type, value: parent.class %> <%= f.hidden_field :commentable_type, value: parent.class %>
<%= f.hidden_field :commentable_id, value: parent.id %> <%= f.hidden_field :commentable_id, value: parent.id %>
<%= f.submit 'Publicar comentario' %> <%= f.submit 'Publicar comentario' %>
<% end %> <% end %>
</div>