Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8593559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:01:11+00:00 2026-06-12T00:01:11+00:00

I am trying to access attributes about the current_user inside my controllers. class MatchfinderController

  • 0

I am trying to access attributes about the current_user inside my controllers.

class MatchfinderController < ApplicationController

  def c(value, t_array)
    t_array.min{|a,b|  (value-a).abs <=> (value-b).abs }
  end

  def show 
    peeps = User.find(:all, :conditions => ["id != ?", current_user.id])
    user_a = []

    peeps.each do |user|  
      user_a.push user.rating    
    end

    closest_rating = c(current_user.rating, user_a)

    @opponent = User.find(:all, :conditions => ["id != ? AND rating = ? ", current_user.id, closest_rating])
  end
end

current_user is working in the view just fine however returns nil in the controller.

Here is my SessionsHelper.

module SessionsHelper

  def sign_in(user)
    cookies.permanent[:remember_token] = user.remember_token
    self.current_user = user
  end

  def current_user=(user)
    @current_user = user
  end

  def current_user
    @current_user ||= User.find_by_remember_token(cookies[:remember_token])
  end

  def signed_in?
    !current_user.nil?
  end
end

The SessionsHelper is included by ApplicationController

class ApplicationController < ActionController::Base
  protect_from_forgery
  include SessionsHelper
end

Here is my SessionsController

class SessionsController < ApplicationController
  def new
  end

  def create
    user = User.find_by_email(params[:email])
    if user && user.authenticate(params[:password])
      sign_in user
      redirect_to root_url, notice: "Logged in!"
    else
      flash.now.alert = "Email or password is invalid"
      render "new"
    end
  end

  def destroy
    cookies[:remember_token] = nil
    redirect_to root_url, notice: "Logged out!"
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:01:12+00:00Added an answer on June 12, 2026 at 12:01 am

    put your code in application controller and mark it as helper_method in this way you can use that method in both helper as well as controller

    helper_method :current_user
    
    def current_user=(user)
      @current_user = user
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m trying to add authorize attributes to some of my MVC4 controllers, and they
I am trying to access a C++ class and call its method from a
Trying to access file attributes from an input field after a file is selected.
I'm trying to access a WCF service, exposed using basicHttpBinding, inside an ASP.NET 2.0
I'm working in the simulator right now and when trying to access the attributes
I'm trying to access attribute with interpolation (Saas 3), but get an error. @each
Trying to access a Servlet from a button on HTML page //Html Page FORM
When trying to access the database, I am unable to access the column. I
Im trying to access the Magento customer session in another part of my website.
Im trying to access a Sql CE 2005 database on a windows mobile device

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.