* Moves badge_achievement-related code from /admin/bagdes to /admin/badge_achievements - Adds an Admin::BadgeAchievements::Controller - Moves #award and #award_badges to Admin::BadgeAchievements::Controller - Removes #award and #award_badges from Admin::Badges::Controller - Moves award.html.erb from /admin/badges to /admin/badge_achievements - Removes badge_achievement routes from /admin/badges - Adds a redirect for /admin/badges/badge_achievements to routes.rb - Cleans up and refactors code in controllers, views, and routes * Add more actions to Admin::BadgeAchievements::Controller and matching routes - Adds an #index and #destory action to the BadgeAchievements::Controller - Adds destroy to the badge_achievements routes - Adjusts redirects for badge_achievements in routes.rb - Removes dead code from the index view for Badges - Refactors the existing code in the index view for BadgeAchievements * Adds an /admin/badge_achievements_spec and cleans up the /admin/badges_spec - Removes the badge_achievement-related tests from badges_spec.rb - Adds an additional test around deleting badge_achievements * Add pagination to badge_achievements index view * Adds badge_achievements to Admin menu items and add comment to routes.rb -Add badge_achievements to the Admin nav bar -Add a comment regarding redirects for badge_achievements * Resolve JS console stacktrace notices and change wording on deletion buttons * Add a Back to Badge Achievements button to the badge award form * Adjust styling to fix failing /admin/badges_spec.rb * Uses SQL paging to optimize scalibility and adds search functionality to index.html.erb - Use SQL paging in Admin::BadgeAchievements::Controller in #index and #award - Add a search by user ID to Badge Achievements index view - Add a limit of 15 badges to be shown on the Badge Achievement index view - Add a User ID column to the Badge Achievement index view * Add Award Badge button back to Badge Achievement index.html.erb * Change @badge to be more explicit and reword warning around badge deletion * Adds award badge button back, rewords success message, and adjusts SQL paging
47 lines
943 B
Ruby
47 lines
943 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)
|
|
end
|
|
end
|
|
end
|