I have a sessionsController and I’m trying to add a redirect_back_or method in my sessions_helper to allow friendly forwarding.
Here is the error I get:
undefined method `redirect_back_or' for #<SessionsController:0x007f9fa1b51ec0>
I have restarted the server and can’t figure out why it’s not finding this method in my helper.
My Sessions helper code is as follows:
module SessionsHelper
def deny_access
store_location
redirect_to signin_path, :notice => "Please sign in to access this page."
end
def redirect_back_or(default)
redirect_to(session[:return_to] || default)
clear_return_to
end
private
def store_location
session[:return_to] = request.fullpath
end
def clear_return_to
session[:return_to] = nil
end
end
My sessions controller is
class SessionsController < ApplicationController
def create
auth = request.env["omniauth.auth"]
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
session[:user_id] = user.id
redirect_back_or user
#redirect_to root_url, :notice => "Signed in!"
end
def destroy
session[:user_id] = nil
redirect_to root_url, :notice => "Signed out!"
end
end
Put that method in
ApplicationController:Or include the
SessionsHelpermodule in your controller to use the method: