rosa-build/app/controllers/projects/hooks_controller.rb

45 lines
1.1 KiB
Ruby
Raw Normal View History

class Projects::HooksController < Projects::BaseController
2015-03-04 23:19:19 +00:00
before_action :authenticate_user!
before_action -> { authorize @project, :update? }
# load_and_authorize_resource :project
# load_and_authorize_resource :hook, through: :project
2013-04-15 12:47:53 +01:00
def index
@name = params[:name]
2013-04-15 10:40:41 +01:00
@hooks = @project.hooks.for_name(@name).order('name asc, created_at desc')
2013-05-16 12:36:29 +01:00
render(:show) if @name.present?
end
def new
end
def edit
end
def create
if @hook.save
2014-01-21 04:51:49 +00:00
redirect_to project_hooks_path(@project, name: @hook.name), notice: t('flash.hook.created')
else
flash[:error] = t('flash.hook.save_error')
flash[:warning] = @hook.errors.full_messages.join('. ')
render :new
end
end
def update
if @hook.update_attributes(params[:hook])
2014-01-21 04:51:49 +00:00
redirect_to project_hooks_path(@project, name: @hook.name), notice: t('flash.hook.updated')
else
flash[:error] = t('flash.hook.save_error')
flash[:warning] = @hook.errors.full_messages.join('. ')
render :edit
end
end
def destroy
@hook.destroy
2014-01-21 04:51:49 +00:00
redirect_to project_hooks_path(@project, name: @hook.name)
end
2013-04-15 12:47:53 +01:00
end