AutoCommit Fre Jul 31 23:03:01 CEST 2015

This commit is contained in:
Andreas Stephanides
2015-07-31 23:03:01 +02:00
parent 4bb81ef9d1
commit 786cde0d08
5 changed files with 20 additions and 18 deletions

View File

@@ -1,7 +1,8 @@
class CommentsController < ApplicationController class CommentsController < ApplicationController
def index def index
@commentable=params[:commentable_type].constantize.find(params[:commentable_id]) unless params[:commentable_type].nil? or params[:commentable_id].nil? @commentable=params[:commentable_type].constantize.find(params[:commentable_id]) unless params[:commentable_type].nil? or params[:commentable_id].nil?
@comments=@commentable.comments.order(:created_at).roots.page(params[:page]).per(2).reverse_order num = {"Beispiel"=> 2, "Survey::Question"=> 7}
@comments=@commentable.comments.order(:created_at).roots.page(params[:page]).per(num[params[:commentable_type]]).reverse_order
respond_to do |format| respond_to do |format|
format.html # new.html.erb format.html # new.html.erb
format.json { render json: @comment } format.json { render json: @comment }
@@ -84,12 +85,13 @@ class CommentsController < ApplicationController
def destroy def destroy
@comment = Comment.find(params[:id]) @comment = Comment.find(params[:id])
@commentable=@comment.commentable @commentable=@comment.commentable
@divid=@comment.divid
@comment.destroy @comment.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to @commentable, :action=>"show"} format.html { redirect_to @commentable, :action=>"show"}
format.json { head :no_content } format.json { head :no_content }
format.js
end end
end end
end end

View File

@@ -1,9 +1,10 @@
<div id="<%= comment.divid %>"> <div id="<%= comment.divid %>">
<a class="pull-left media-object" href="#"><%= image_tag comment.thumb_url %></a> <a class="pull-left media-object" href="#"><%= image_tag comment.thumb_url %></a>
<div class="media-body"> <div class="media-body">
<b><%= (!comment.anonym) ? comment.user.try(:email) : "Anonym" %></b> (<%= I18n.l(comment.created_at) %>)
<b><%= (!comment.anonym) ? comment.user.try(:email) : "Anonym" %></b> (<%= I18n.l(comment.created_at) %>) <%= link_to ffi1_icon("remove9"), comment, method: :delete, data: { confirm: 'Are you sure?' } %>: <%= link_to ffi1_icon("remove9"), comment, method: :delete, data: { confirm: 'Are you sure?' }, remote: true %>:
<p><%= comment.text %> <p>
<%= comment.text %>
<% if can?(:comment, comment.commentable) %> <% if can?(:comment, comment.commentable) %>
<br><%= link_to "comment" , new_comment_path( commentable_type: "Comment", commentable_id: comment.id), remote:true %> <br><%= link_to "comment" , new_comment_path( commentable_type: "Comment", commentable_id: comment.id), remote:true %>
<% end %> <% end %>
@@ -12,8 +13,5 @@
</div> </div>
<%= render partial:"comments/comments", object: comment.children.order(:created_at).reverse_order if comment.children.size >0 %> <%= render partial:"comments/comments", object: comment.children.order(:created_at).reverse_order if comment.children.size >0 %>
</div> </div>
</div> </div>

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1 @@
$('#<%= @divid %>').remove()