From 270f42bba1bbade2b019726cf80389c1fd82470d Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 2 Aug 2015 15:03:01 +0200 Subject: [PATCH] AutoCommit Son Aug 2 15:03:01 CEST 2015 --- app/controllers/comments_controller.rb | 19 ++++++------------- .../survey/questions_controller.rb | 10 +--------- app/views/comments/hide.js.erb | 2 +- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 03ef993..47d40b7 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -3,12 +3,10 @@ class CommentsController < ApplicationController before_filter :decode_commentable_type 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.accessible_by(current_ability, :show).page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order - + @comments=@commentable.comments.order(:created_at).roots.accessible_by(current_ability, :show).page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order respond_to do |format| 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? @@ -62,18 +60,14 @@ class CommentsController < ApplicationController # PUT /comments/1 # PUT /comments/1.json def update - params[:comment].select! {|i| !["commentable_id", "commentable_type"].include?(i)} @comment = Comment.find(params[:id]) @comment.commentable=params[:comment][:commentable_type].constantize.find(params[:comment][:commentable_id]) unless params[:comment][:commentable_type].nil? or params[:comment][:commentable_id].nil? respond_to do |format| - if @comment.update_attributes(params[:comment]) format.html { redirect_to @comment.commentable, notice: 'Comment was successfully updated.' } - format.json { head :no_content } else format.html { render action: "edit" } - format.json { render json: @comment.errors, status: :unprocessable_entity } end end end @@ -86,13 +80,12 @@ class CommentsController < ApplicationController @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.js end end -private -def decode_commentable_type - params[:commentable_type].gsub!("_","::") unless params[:commentable_type].nil? -end - + private + def decode_commentable_type + params[:commentable_type].gsub!("_","::") unless params[:commentable_type].nil? + end + end diff --git a/app/controllers/survey/questions_controller.rb b/app/controllers/survey/questions_controller.rb index d8d3453..0e88883 100644 --- a/app/controllers/survey/questions_controller.rb +++ b/app/controllers/survey/questions_controller.rb @@ -7,7 +7,6 @@ class Survey::QuestionsController < ApplicationController @survey_questions = Survey::Question.all respond_to do |format| format.html # index.html.erb - format.json { render json: @survey_questions } end end def answer @@ -34,7 +33,6 @@ class Survey::QuestionsController < ApplicationController respond_to do |format| format.html # show.html.erb - format.json { render json: @survey_question } end end @@ -42,10 +40,8 @@ class Survey::QuestionsController < ApplicationController # GET /survey/questions/new.json def new @survey_question = Survey::Question.new - respond_to do |format| format.html # new.html.erb - format.json { render json: @survey_question } end end @@ -62,10 +58,8 @@ class Survey::QuestionsController < ApplicationController respond_to do |format| if @survey_question.save format.html { redirect_to @survey_question, notice: 'Question was successfully created.' } - format.json { render json: @survey_question, status: :created, location: @survey_question } else format.html { render action: "new" } - format.json { render json: @survey_question.errors, status: :unprocessable_entity } end end end @@ -78,10 +72,8 @@ class Survey::QuestionsController < ApplicationController respond_to do |format| if @survey_question.update_attributes(params[:survey_question]) format.html { redirect_to @survey_question, notice: 'Question was successfully updated.' } - format.json { head :no_content } else format.html { render action: "edit" } - format.json { render json: @survey_question.errors, status: :unprocessable_entity } end end end @@ -94,7 +86,7 @@ class Survey::QuestionsController < ApplicationController respond_to do |format| format.html { redirect_to survey_questions_url } - format.json { head :no_content } + end end end diff --git a/app/views/comments/hide.js.erb b/app/views/comments/hide.js.erb index 53ca8af..35ec342 100644 --- a/app/views/comments/hide.js.erb +++ b/app/views/comments/hide.js.erb @@ -1,3 +1,3 @@ $("#<%= Comment.wrapid_for(@commentable) %>").html("<%= escape_javascript "" %>") -$("#<%= Comment.switchshowid_for(@commentable) %>").attr("href","<%= escape_javascript comments_path(commentable_type: @commentable.class.to_s, commentable_id: @commentable.id) %>") +$("#<%= Comment.switchshowid_for(@commentable) %>").replaceWith("<%= escape_javascript link_to "Comments...", comments_path(commentable_type: @commentable.class.to_s, commentable_id: @commentable.id) %>")