Last active
August 29, 2015 14:13
-
-
Save andrzejkrzywda/a4055d57cd106fbf3256 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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