From 8edbef39655d0c67d105002d546e298e3dbfd88e Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Fri, 9 Dec 2016 11:56:53 +1030 Subject: [PATCH] Rubocop --- app/controllers/likes_controller.rb | 31 +++++++++++++---------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 41aeb337a..b36b8114c 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -1,6 +1,6 @@ class LikesController < ApplicationController - before_action :authenticate_member!, :except => :index - + before_action :authenticate_member!, except: :index + respond_to :html, :json def create @@ -11,19 +11,19 @@ class LikesController < ApplicationController respond_to do |format| if @like.save format.html { redirect_to @like.likeable } - format.json { - render({ + format.json do + render( json: { id: @like.likeable.id, liked_by_member: true, description: ActionController::Base.helpers.pluralize(@like.likeable.likes.count, "like"), url: like_path(@like, format: :json) - }, + }, status: 201 - }) - } + ) + end else - format.html do + format.html do flash[:error] = 'Unable to like' redirect_to @like.likeable end @@ -37,17 +37,17 @@ class LikesController < ApplicationController respond_to do |format| if like.destroy format.html { redirect_to likeable } - format.json { - render({ + format.json do + render( json: { id: likeable.id, liked_by_member: false, description: ActionController::Base.helpers.pluralize(likeable.likes.count, "like"), url: likes_path(Like.new, "#{likeable.class.name.underscore}_id", likeable.id, format: :json) - }, + }, status: 200 - }) - } + ) + end else format.html do flash[:error] = 'Unable to unlike' @@ -61,14 +61,11 @@ class LikesController < ApplicationController def find_likeable params.each do |name, value| - if name =~ /(.+)_id$/ - return $1.classify.constantize.find(value) - end + return $1.classify.constantize.find(value) if name =~ /(.+)_id$/ end end def like_params params.require(:like).permit(:member, :likeable) end - end