2014-03-05 20:52:20 +08:00
|
|
|
class Admin::BadgesController < Admin::AdminController
|
|
|
|
def badge_types
|
|
|
|
badge_types = BadgeType.all.to_a
|
|
|
|
render_serialized(badge_types, BadgeTypeSerializer, root: "badge_types")
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
badge = Badge.new
|
|
|
|
update_badge_from_params(badge)
|
|
|
|
badge.save!
|
|
|
|
render_serialized(badge, BadgeSerializer, root: "badge")
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
badge = find_badge
|
|
|
|
update_badge_from_params(badge)
|
|
|
|
badge.save!
|
|
|
|
render_serialized(badge, BadgeSerializer, root: "badge")
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
find_badge.destroy
|
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def find_badge
|
|
|
|
params.require(:id)
|
|
|
|
Badge.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_badge_from_params(badge)
|
2014-05-21 15:22:42 +08:00
|
|
|
params.permit(:name, :description, :badge_type_id, :allow_title, :multiple_grant)
|
2014-03-05 20:52:20 +08:00
|
|
|
badge.name = params[:name]
|
|
|
|
badge.description = params[:description]
|
|
|
|
badge.badge_type = BadgeType.find(params[:badge_type_id])
|
2014-04-26 02:25:29 +08:00
|
|
|
badge.allow_title = params[:allow_title]
|
2014-05-21 15:22:42 +08:00
|
|
|
badge.multiple_grant = params[:multiple_grant]
|
2014-06-10 15:32:22 +08:00
|
|
|
badge.icon = params[:icon]
|
2014-03-05 20:52:20 +08:00
|
|
|
badge
|
|
|
|
end
|
|
|
|
end
|