factor out map_scope function
This commit is contained in:
parent
bb87c9c2db
commit
f75ad41a82
1 changed files with 10 additions and 13 deletions
|
@ -9,8 +9,7 @@ class ExploreController < ApplicationController
|
||||||
|
|
||||||
# GET /explore/active
|
# GET /explore/active
|
||||||
def active
|
def active
|
||||||
@maps = policy_scope(Map).order(updated_at: :desc)
|
@maps = map_scope(Map)
|
||||||
.page(params[:page]).per(20)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
|
@ -24,8 +23,7 @@ class ExploreController < ApplicationController
|
||||||
|
|
||||||
# GET /explore/featured
|
# GET /explore/featured
|
||||||
def featured
|
def featured
|
||||||
@maps = policy_scope(Map).where(featured: true).order(updated_at: :desc)
|
@maps = map_scope(Map.where(featured: true))
|
||||||
.page(params[:page]).per(20)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@maps, @user) }
|
format.html { respond_with(@maps, @user) }
|
||||||
|
@ -35,8 +33,7 @@ class ExploreController < ApplicationController
|
||||||
|
|
||||||
# GET /explore/mine
|
# GET /explore/mine
|
||||||
def mine
|
def mine
|
||||||
@maps = policy_scope(Map).where(user_id: current_user.id)
|
@maps = map_scope(Map.where(user_id: current_user.id))
|
||||||
.order(updated_at: :desc).page(params[:page]).per(20)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@maps, @user) }
|
format.html { respond_with(@maps, @user) }
|
||||||
|
@ -46,8 +43,7 @@ class ExploreController < ApplicationController
|
||||||
|
|
||||||
# GET /explore/shared
|
# GET /explore/shared
|
||||||
def shared
|
def shared
|
||||||
@maps = policy_scope(Map).where(id: current_user.shared_maps.map(&:id))
|
@maps = map_scope(Map.where(id: current_user.shared_maps.map(&:id)))
|
||||||
.order(updated_at: :desc).page(params[:page]).per(20)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@maps, @user) }
|
format.html { respond_with(@maps, @user) }
|
||||||
|
@ -57,9 +53,7 @@ class ExploreController < ApplicationController
|
||||||
|
|
||||||
# GET /explore/starred
|
# GET /explore/starred
|
||||||
def starred
|
def starred
|
||||||
stars = current_user.stars.map(&:map_id)
|
@maps = map_scope(Map.where(id: current_user.stars.map(&:map_id)))
|
||||||
@maps = policy_scope(Map).where(id: stars).order(updated_at: :desc)
|
|
||||||
.page(params[:page]).per(20)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@maps, @user) }
|
format.html { respond_with(@maps, @user) }
|
||||||
|
@ -70,8 +64,7 @@ class ExploreController < ApplicationController
|
||||||
# GET /explore/mapper/:id
|
# GET /explore/mapper/:id
|
||||||
def mapper
|
def mapper
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
@maps = policy_scope(Map.where(user: @user))
|
@maps = map_scope(Map.where(user: @user))
|
||||||
.order(updated_at: :desc).page(params[:page]).per(20)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@maps, @user) }
|
format.html { respond_with(@maps, @user) }
|
||||||
|
@ -81,6 +74,10 @@ class ExploreController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def map_scope(scope)
|
||||||
|
policy_scope(scope).order(updated_at: :desc).page(params[:page]).per(20)
|
||||||
|
end
|
||||||
|
|
||||||
def authorize_explore
|
def authorize_explore
|
||||||
authorize :Explore
|
authorize :Explore
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue