Skip to content

Instantly share code, notes, and snippets.

@kibaekr
Created July 9, 2012 21:19
Show Gist options
  • Save kibaekr/3079018 to your computer and use it in GitHub Desktop.
Save kibaekr/3079018 to your computer and use it in GitHub Desktop.
got the damn routing to finally work!
class ApplicationController < ActionController::Base
protect_from_forgery
#session['user_return_to'] = request.url
def after_sign_in_path_for(resource)
sign_in_url = "http://localhost:3000/users/sign_in" || "http://onvard.com/users/sign_in" ||
"http://www.onvard.com/users/sign_in" #url_for(:action => 'new', :controller => 'sessions', :only_path => false, :protocol => 'http')
if (request.referer == sign_in_url)
session[:current_path] || env['omniauth.origin'] || request.env['omniauth.origin'] || stored_location_for(resource) || root_path
else
request.referer
end
end
private
def store_location
if user_signed_in?
else
session[:original_page] = request.referer
session[:current_path] = "http://localhost:3000" + request.fullpath
puts 'aaaaaaaaa below is page a, which should be missions_path'
puts session[:original_page]
puts 'aaaaaaaaaa below should be votes'
puts session[:current_path]
end
end
end
class MissionsController < ApplicationController
before_filter :store_location
before_filter :authenticate_user!, :except => [:show, :index]
def vote_for_mission
@mission = Mission.find(params[:id])
puts 'vvvvvvv22 below is original page that should be missions_path, not user sign in'
puts session[:original_page]
if @mission.voted_by?(current_user)
redirect_to (session[:original_page] || request.referer), alert: 'You already voted on this mission.'
else
@mission.increment!(:karma)
@mission.active = true
@mission.real_author.increment!(:userpoints) unless @mission.real_author.blank?
current_user.vote_for(@mission)
redirect_to (session[:original_page] || request.referer), notice: 'Your vote was successfully recorded.'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment