From f3e58009efc92867b16b6e1a0439ccf2d65cd416 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Fri, 25 Apr 2014 11:37:17 -0400 Subject: [PATCH] adding code climate, removing duplication --- README.md | 2 +- app/controllers/campaigns_controller.rb | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 5302497..e526ea9 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ Vidpush ======= [![Build Status](https://circleci.com/gh/propelmarketing/vidpush.png?circle-token=46474007c0807cf4b467fb96d7736422b2fa58a7)](https://circleci.com/gh/propelmarketing/vidpush) - +[![Code Climate](https://codeclimate.com/repos/535a76efe30ba01da902dc6b/badges/f1bfeadbed33f25ef547/gpa.png)](https://codeclimate.com/repos/535a76efe30ba01da902dc6b/feed) diff --git a/app/controllers/campaigns_controller.rb b/app/controllers/campaigns_controller.rb index f28179b..a21549d 100644 --- a/app/controllers/campaigns_controller.rb +++ b/app/controllers/campaigns_controller.rb @@ -33,10 +33,7 @@ class CampaignsController < ApplicationController format.html { redirect_to campaign_path(@campaign.listingcode), notice: 'Campaign was successfully created.' } end else - respond_to do |format| - format.json { render json: {error: @campaign.errors.full_messages } } - format.html { render action: 'new' } - end + show_errors('new') end end @@ -44,10 +41,7 @@ class CampaignsController < ApplicationController if @campaign.update(campaign_params) redirect_to campaign_path(@campaign.listingcode), notice: 'Campaign was successfully updated.' else - respond_to do |format| - format.json { render json: {error: @campaign.errors.full_messages } } - format.html { render action: 'edit' } - end + show_errors('edit') end end @@ -57,6 +51,12 @@ class CampaignsController < ApplicationController end private + def show_errors(where_to) + respond_to do |format| + format.json { render json: {error: @campaign.errors.full_messages } } + format.html { render action: where_to } + end + end def set_campaign @campaign = set_by_options(:campaign, :listingcode) end