extracted common controller behavior in order to reduce code duplication
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user