AutoCommit Son Aug 2 15:03:01 CEST 2015

This commit is contained in:
Andreas Stephanides
2015-08-02 15:03:01 +02:00
parent 15b70ad8c6
commit 270f42bba1
3 changed files with 8 additions and 23 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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) %>")