docbrown/app/controllers/internal/sponsorships_controller.rb
Michael Kohl b06e9901d5
Add ApplicationRecord#errors_as_sentence (#8265)
* Add ApplicationRecord#errors_as_sentence

* Refactor existing uses

* Use errors as sentence more consistently
2020-06-04 16:02:41 +02:00

38 lines
1.1 KiB
Ruby

class Internal::SponsorshipsController < Internal::ApplicationController
layout "internal"
def index
@sponsorships = Sponsorship.includes(:organization, :user).order("created_at desc").page(params[:page]).per(50)
end
def edit
@sponsorship = Sponsorship.find(params[:id])
end
def update
@sponsorship = Sponsorship.find(params[:id])
if @sponsorship.update(sponsorship_params)
flash[:notice] = "Sponsorship was successfully updated"
redirect_to internal_sponsorships_path
else
flash[:danger] = @sponsorship.errors_as_sentence
render action: :edit
end
end
def destroy
@sponsorship = Sponsorship.find(params[:id])
if @sponsorship.destroy
flash[:notice] = "Sponsorship was successfully destroyed"
else
flash[:danger] = "Sponsorship was not destroyed"
end
redirect_to internal_sponsorships_path
end
private
def sponsorship_params
params.require(:sponsorship).permit(%i[status expires_at tagline url blurb_html featured_number instructions instructions_updated_at])
end
end