Skip to content

Instantly share code, notes, and snippets.

@andrzejkrzywda
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrzejkrzywda/a4055d57cd106fbf3256 to your computer and use it in GitHub Desktop.
Save andrzejkrzywda/a4055d57cd106fbf3256 to your computer and use it in GitHub Desktop.
class PicturesController < ApplicationController
def index
if confirm_params_or_redirect(params)
redirect_to root_path(:view => @view, :filter => @filter) and return
end
Picture.find(@view, @filter)
end
private
def confirm_params_or_redirect(params)
redirect = false
if !current_user and params[:view] != "all"
@view = session[:view] = params[:view] = "all"
redirect = true
end
if params[:view] and %w(all followed).include? params[:view]
@view = session[:view] = params[:view]
elsif session[:view]
@view = session[:view]
redirect = true
else
@view = "all"
redirect = true
end
if params[:filter] and %w(hot popular recent liked).include? params[:filter][0]
if %w(popular liked).include? params[:filter][0]
if %w(day hour month all).include? params[:filter][1]
@filter = session[:filter] = params[:filter]
else
@filter = session[:filter]
redirect = true
end
else
@filter = session[:filter] = params[:filter]
end
elsif session[:filter]
@filter = session[:filter]
redirect = true
else
@filter = ["hot"]
redirect = true
end
return redirect
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment