diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 0c95d0d..a703a10 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -6,36 +6,26 @@ before_filter :decode_commentable_type @comments=@commentable.comments.order(:created_at).roots.page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order respond_to do |format| format.html # new.html.erb - format.json { render json: @comment } format.js end end def hide - @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? respond_to do |format| format.js - end - + end end def show @comment = Comment.find(params[:id]) - - respond_to do |format| -# format.html # show.html.erb format.js - format.json { render json: @comment } end end def new @comment = Comment.new @comment.commentable=params[:commentable_type].constantize.find(params[:commentable_id]) unless params[:commentable_type].nil? or params[:commentable_id].nil? - - respond_to do |format| - format.html # new.html.erb - format.json { render json: @comment } format.js end end @@ -53,19 +43,16 @@ before_filter :decode_commentable_type c = params[:comment][:commentable_type].constantize.find(params[:comment][:commentable_id]) unless params[:comment][:commentable_type].nil? or params[:comment][:commentable_id].nil? @comment = Comment.build_for(c, current_user,"", params_new) + if @comment.parent_object.class==Comment - @comments= @comment.parent_object.children -else - @comments=@comment.parent_object.comments.order(:created_at).roots.page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order -end + @comments= @comment.parent_object.children + else + @comments=@comment.parent_object.comments.order(:created_at).roots.page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order + end respond_to do |format| if @comment - format.html { redirect_to @comment.commentable, notice: 'Comment was successfully created.', show_comments: true } - format.json { render json: @comment, status: :created, location: @comment } format.js else - format.html { render action: "new" } - format.json { render json: @comment.errors, status: :unprocessable_entity } format.js {render action:"new"} end end @@ -95,13 +82,10 @@ end def destroy @comment = Comment.find(params[:id]) @commentable=@comment.commentable - - @comment.destroy @comments=@commentable.comments.order(:created_at).roots.page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order respond_to do |format| - format.html { redirect_to @commentable, :action=>"show"} - format.json { head :no_content } + format.js end end diff --git a/app/models/survey/choice.rb b/app/models/survey/choice.rb index dc0b25d..9f2094e 100644 --- a/app/models/survey/choice.rb +++ b/app/models/survey/choice.rb @@ -1,7 +1,7 @@ class Survey::Choice < ActiveRecord::Base belongs_to :question, class_name: 'Survey::Question' attr_accessible :picture, :sort, :text, :icon, :picture_cache, :remove_picture, :question_id - has_many :answers, class_name: 'Survey::Answer' + has_many :answers, class_name: 'Survey::Answer', dependent: :destroy include ActionView::Helpers::TagHelper mount_uploader :picture, PictureUploader def to_s diff --git a/app/models/survey/question.rb b/app/models/survey/question.rb index a6df7df..83a1ee8 100644 --- a/app/models/survey/question.rb +++ b/app/models/survey/question.rb @@ -1,7 +1,7 @@ class Survey::Question < ActiveRecord::Base attr_accessible :text, :title, :typ, :choice_ids belongs_to :parent, polymorphic: true - has_many :choices + has_many :choices, dependent: :destroy has_many :answers, through: :choices include IsCommentable @@ -22,7 +22,9 @@ class Survey::Question < ActiveRecord::Base cid= cid - found_ids Survey::Answer.where(user_id: user.id, choice_id: found_ids).delete_all else + if self.typ == 0 Survey::Answer.where(user_id: user.id, choice_id: self.choice_ids).delete_all + end end cid.each do |c| if self.choice_ids.include?(c) diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 3fc04ed..faac3f4 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,5 +1,7 @@