diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 5b62df9e..e2c3acaa 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -21,6 +21,7 @@ def new def edit respond_to do |format| format.html + format.js end end @@ -33,9 +34,11 @@ def create if @comment.save format.html { redirect_back fallback_location: root_path, notice: "Comment was successfully created." } format.json { render :show, status: :created, location: @comment } + format.js else format.html { render :new, status: :unprocessable_entity } format.json { render json: @comment.errors, status: :unprocessable_entity } + format.js end end end @@ -46,9 +49,11 @@ def update if @comment.update(comment_params) format.html { redirect_to root_url, notice: "Comment was successfully updated." } format.json { render :show, status: :ok, location: @comment } + format.js else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @comment.errors, status: :unprocessable_entity } + format.js end end end @@ -59,23 +64,28 @@ def destroy respond_to do |format| format.html { redirect_back fallback_location: root_url, notice: "Comment was successfully destroyed." } format.json { head :no_content } + + format.js do + render template: "comments/destroy" + end end end private - # Use callbacks to share common setup or constraints between actions. - def set_comment - @comment = Comment.find(params[:id]) - end - def ensure_current_user_is_owner - if current_user != @comment.author - redirect_back fallback_location: root_url, alert: "You're not authorized for that." - end - end + # Use callbacks to share common setup or constraints between actions. + def set_comment + @comment = Comment.find(params[:id]) + end - # Only allow a list of trusted parameters through. - def comment_params - params.require(:comment).permit(:author_id, :photo_id, :body) + def ensure_current_user_is_owner + if current_user != @comment.author + redirect_back fallback_location: root_url, alert: "You're not authorized for that." end + end + + # Only allow a list of trusted parameters through. + def comment_params + params.require(:comment).permit(:author_id, :photo_id, :body) + end end diff --git a/app/controllers/follow_requests_controller.rb b/app/controllers/follow_requests_controller.rb index 9c30da7c..d96c50dc 100644 --- a/app/controllers/follow_requests_controller.rb +++ b/app/controllers/follow_requests_controller.rb @@ -8,6 +8,7 @@ def index # GET /follow_requests/1 or /follow_requests/1.json def show + format.js end # GET /follow_requests/new @@ -17,6 +18,7 @@ def new # GET /follow_requests/1/edit def edit + format.js end # POST /follow_requests or /follow_requests.json @@ -28,9 +30,11 @@ def create if @follow_request.save format.html { redirect_back fallback_location: root_url, notice: "Follow request was successfully created." } format.json { render :show, status: :created, location: @follow_request } + format.js else format.html { render :new, status: :unprocessable_entity } format.json { render json: @follow_request.errors, status: :unprocessable_entity } + format.js end end end @@ -41,9 +45,11 @@ def update if @follow_request.update(follow_request_params) format.html { redirect_back fallback_location: root_url, notice: "Follow request was successfully updated." } format.json { render :show, status: :ok, location: @follow_request } + format.js else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @follow_request.errors, status: :unprocessable_entity } + format.js end end end @@ -54,6 +60,7 @@ def destroy respond_to do |format| format.html { redirect_back fallback_location: root_url, notice: "Follow request was successfully destroyed." } format.json { head :no_content } + format.js end end diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 49affd3e..21f1460d 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -8,6 +8,7 @@ def index # GET /likes/1 or /likes/1.json def show + format.js end # GET /likes/new @@ -17,6 +18,10 @@ def new # GET /likes/1/edit def edit + respond_to do |format| + format.html + format.js + end end # POST /likes or /likes.json @@ -27,6 +32,7 @@ def create if @like.save format.html { redirect_back fallback_location: root_url, notice: "Like was successfully created." } format.json { render :show, status: :created, location: @like } + format.js else format.html { render :new, status: :unprocessable_entity } format.json { render json: @like.errors, status: :unprocessable_entity } @@ -40,9 +46,11 @@ def update if @like.update(like_params) format.html { redirect_to @like, notice: "Like was successfully updated." } format.json { render :show, status: :ok, location: @like } + format.js else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @like.errors, status: :unprocessable_entity } + format.js end end end @@ -53,17 +61,20 @@ def destroy respond_to do |format| format.html { redirect_back fallback_location: root_url, notice: "Like was successfully destroyed." } format.json { head :no_content } + + format.js end end private - # Use callbacks to share common setup or constraints between actions. - def set_like - @like = Like.find(params[:id]) - end - # Only allow a list of trusted parameters through. - def like_params - params.require(:like).permit(:fan_id, :photo_id) - end + # Use callbacks to share common setup or constraints between actions. + def set_like + @like = Like.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def like_params + params.require(:like).permit(:fan_id, :photo_id) + end end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 7b8dc14d..9ba17c6c 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,4 +1,4 @@ -