2014-04-16 09:12:06 -04:00
|
|
|
class BadgesController < ApplicationController
|
2014-04-25 14:58:41 -04:00
|
|
|
skip_before_filter :check_xhr, only: [:index, :show]
|
|
|
|
|
2014-04-16 09:12:06 -04:00
|
|
|
def index
|
|
|
|
badges = Badge.all.to_a
|
2014-04-25 14:58:41 -04:00
|
|
|
serialized = MultiJson.dump(serialize_data(badges, BadgeSerializer, root: "badges"))
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
store_preloaded "badges", serialized
|
|
|
|
render "default/empty"
|
|
|
|
end
|
|
|
|
format.json { render json: serialized }
|
|
|
|
end
|
2014-04-16 09:12:06 -04:00
|
|
|
end
|
2014-04-16 10:56:11 -04:00
|
|
|
|
|
|
|
def show
|
|
|
|
params.require(:id)
|
|
|
|
badge = Badge.find(params[:id])
|
2014-06-14 03:55:06 -04:00
|
|
|
|
|
|
|
if current_user
|
|
|
|
user_badge = UserBadge.find_by(user_id: current_user.id, badge_id: badge.id)
|
|
|
|
if user_badge && user_badge.notification
|
|
|
|
user_badge.notification.update_attributes read: true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-25 14:58:41 -04:00
|
|
|
serialized = MultiJson.dump(serialize_data(badge, BadgeSerializer, root: "badge"))
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
store_preloaded "badge", serialized
|
|
|
|
render "default/empty"
|
|
|
|
end
|
|
|
|
format.json { render json: serialized }
|
|
|
|
end
|
2014-04-16 10:56:11 -04:00
|
|
|
end
|
2014-04-16 09:12:06 -04:00
|
|
|
end
|