diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index fe95fd5..b6aeb7b 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,7 +1,8 @@ class CommentsController < ApplicationController def index @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| format.html # new.html.erb format.json { render json: @comment } @@ -84,12 +85,13 @@ class CommentsController < ApplicationController def destroy @comment = Comment.find(params[:id]) @commentable=@comment.commentable + @divid=@comment.divid @comment.destroy respond_to do |format| format.html { redirect_to @commentable, :action=>"show"} format.json { head :no_content } - + format.js end end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 95c1630..317c539 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -43,9 +43,9 @@ class Comment < ActiveRecord::Base "comment_" + id.to_s end def formid -"comment_form_" + commentable_type.gsub(":","_") + "_" + commentable_id.to_s + "comment_form_" + commentable_type.gsub(":","_") + "_" + commentable_id.to_s end def self.formid_for(c) "comment_form_" + c.class.to_s.gsub(":","_") + "_" + c.id.to_s - end + end end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 2740c2f..6468ee6 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,19 +1,17 @@
<%= image_tag comment.thumb_url %>
+ <%= (!comment.anonym) ? comment.user.try(:email) : "Anonym" %> (<%= I18n.l(comment.created_at) %>) + <%= link_to ffi1_icon("remove9"), comment, method: :delete, data: { confirm: 'Are you sure?' }, remote: true %>: +

+ <%= comment.text %> + <% if can?(:comment, comment.commentable) %> +
<%= link_to "comment" , new_comment_path( commentable_type: "Comment", commentable_id: comment.id), remote:true %> + <% end %> +

+
+
- <%= (!comment.anonym) ? comment.user.try(:email) : "Anonym" %> (<%= I18n.l(comment.created_at) %>) <%= link_to ffi1_icon("remove9"), comment, method: :delete, data: { confirm: 'Are you sure?' } %>: -

<%= comment.text %> -<% if can?(:comment, comment.commentable) %> -
<%= link_to "comment" , new_comment_path( commentable_type: "Comment", commentable_id: comment.id), remote:true %> -<% end %> -

-
-
- - <%= 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 %> +
diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/app/views/comments/create.js.erb @@ -0,0 +1 @@ + diff --git a/app/views/comments/destroy.js.erb b/app/views/comments/destroy.js.erb new file mode 100644 index 0000000..389d41d --- /dev/null +++ b/app/views/comments/destroy.js.erb @@ -0,0 +1 @@ +$('#<%= @divid %>').remove()