fiddle with maps_controller code style

This commit is contained in:
Devin Howard 2016-02-09 11:20:04 +08:00
parent 451ed81010
commit 0b98e446ca

View file

@ -1,5 +1,4 @@
class MapsController < ApplicationController class MapsController < ApplicationController
before_filter :require_user, only: [:create, :update, :screenshot, :destroy] before_filter :require_user, only: [:create, :update, :screenshot, :destroy]
respond_to :html, :json respond_to :html, :json
@ -10,38 +9,24 @@ class MapsController < ApplicationController
# GET /explore/featured # GET /explore/featured
# GET /explore/mapper/:id # GET /explore/mapper/:id
def index def index
return redirect_to activemaps_url if request.path == "/explore"
if request.path == "/explore"
redirect_to activemaps_url and return
end
@current = current_user @current = current_user
@user = nil
@maps = [] @maps = []
@mapperId = nil page = params[:page].present ? params[:page] : 1
if !params[:page]
page = 1
else
page = params[:page]
end
if request.path.index("/explore/active") != nil if request.path.index("/explore/active") != nil
@maps = Map.where("maps.permission != ?", "private").order("updated_at DESC").page(page).per(20) @maps = Map.where("maps.permission != ?", "private").order("updated_at DESC").page(page).per(20)
@request = "active" @request = "active"
elsif request.path.index("/explore/featured") != nil elsif request.path.index("/explore/featured") != nil
@maps = Map.where("maps.featured = ? AND maps.permission != ?", true, "private").order("updated_at DESC").page(page).per(20) @maps = Map.where("maps.featured = ? AND maps.permission != ?", true, "private").order("updated_at DESC").page(page).per(20)
@request = "featured" @request = "featured"
elsif request.path.index('/explore/mine') != nil # looking for maps by me elsif request.path.index('/explore/mine') != nil # looking for maps by me
if !authenticated? return redirect_to activemaps_url if !authenticated?
redirect_to activemaps_url and return
end
# don't need to exclude private maps because they all belong to you # don't need to exclude private maps because they all belong to you
@maps = Map.where("maps.user_id = ?", @current.id).order("updated_at DESC").page(page).per(20) @maps = Map.where("maps.user_id = ?", @current.id).order("updated_at DESC").page(page).per(20)
@request = "you" @request = "you"
elsif request.path.index('/explore/mapper/') != nil # looking for maps by a mapper elsif request.path.index('/explore/mapper/') != nil # looking for maps by a mapper
@user = User.find(params[:id]) @user = User.find(params[:id])
@maps = Map.where("maps.user_id = ? AND maps.permission != ?", @user.id, "private").order("updated_at DESC").page(page).per(20) @maps = Map.where("maps.user_id = ? AND maps.permission != ?", @user.id, "private").order("updated_at DESC").page(page).per(20)