docbrown/app/controllers/admin/badges_controller.rb
Anna Buianova 40b989ca62
Configure badge credits by admins (#13145)
* Added credits_awarded to /admin/badges forms

* Award credits only if badge has them

* Removed information about credits and listings in the new badge email when not needed

* Specs for number of credits awarded for badges

* Added missing newline

* Fix typo

Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>

* Improve new_badge_email.text.erb

Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>

* Fixed number of credits in notification

* Added specs for number of credits in notifications

Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>
2021-03-30 10:58:48 +03:00

47 lines
961 B
Ruby

module Admin
class BadgesController < Admin::ApplicationController
layout "admin"
def index
@badges = Badge.all
end
def new
@badge = Badge.new
end
def edit
@badge = Badge.find(params[:id])
end
def create
@badge = Badge.new(badge_params)
if @badge.save
flash[:success] = "Badge has been created!"
redirect_to admin_badges_path
else
flash[:danger] = @badge.errors_as_sentence
render new_admin_badge_path
end
end
def update
@badge = Badge.find(params[:id])
if @badge.update(badge_params)
flash[:success] = "Badge has been updated!"
redirect_to admin_badges_path
else
flash[:danger] = @badge.errors_as_sentence
render :edit
end
end
private
def badge_params
params.require(:badge).permit(:title, :slug, :description, :badge_image, :credits_awarded)
end
end
end