extracted common controller behavior in order to reduce code duplication

This commit is contained in:
Hauke Klement
2015-02-05 12:28:09 +01:00
parent 74398b9939
commit a22a5af711
12 changed files with 96 additions and 186 deletions

View File

@ -1,4 +1,6 @@
class ConsumersController < ApplicationController
include CommonBehavior
before_action :set_consumer, only: MEMBER_ACTIONS
def authorize!
@ -9,23 +11,11 @@ class ConsumersController < ApplicationController
def create
@consumer = Consumer.new(consumer_params)
authorize!
respond_to do |format|
if @consumer.save
format.html { redirect_to(@consumer, notice: t('shared.object_created', model: Consumer.model_name.human)) }
format.json { render(:show, location: @consumer, status: :created) }
else
format.html { render(:new) }
format.json { render(json: @consumer.errors, status: :unprocessable_entity) }
end
end
create_and_respond(object: @consumer)
end
def destroy
@consumer.destroy
respond_to do |format|
format.html { redirect_to(consumers_url, notice: t('shared.object_destroyed', model: Consumer.model_name.human)) }
format.json { head(:no_content) }
end
destroy_and_respond(object: @consumer)
end
def edit
@ -56,14 +46,6 @@ class ConsumersController < ApplicationController
end
def update
respond_to do |format|
if @consumer.update(consumer_params)
format.html { redirect_to(@consumer, notice: t('shared.object_updated', model: Consumer.model_name.human)) }
format.json { render(:show, location: @consumer, status: :ok) }
else
format.html { render(:edit) }
format.json { render(json: @consumer.errors, status: :unprocessable_entity) }
end
end
update_and_respond(object: @consumer, params: consumer_params)
end
end