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

  • SEARCH
  • Home
  • 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 7672133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:12:58+00:00 2026-05-31T16:12:58+00:00

I thought methods such as name and email were default in rails? In my

  • 0

I thought methods such as name and email were default in rails?

In my static pages view, in profile.html.erb I have:

<% if logged_in? %>
<% provide(:title, @user.name) %>
<% else %>
<% provide(:title, 'Profile')%>
<% end %>

I put in my static_page_controller

def profile
  @user = User.find_by_remember_token(:remember_token)
end

When I go to the console User.find_by_remember_token(“actualtoken”).name returns me the appropriate users name, but :remember_token does not. How do I make :remember_token = the logged in users remember token?

In my sessions_helper I have

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

  def logged_in?
    !current_user.nil?
  end

  def current_user=(user)
    @current_user = user
  end

  def current_user
      @current_user ||= user_from_remember_token
  end

  def log_out
    current_user = nil
    cookies.delete(:remember_token)
  end


    private

    def user_from_remember_token
      remember_token = cookies[:remember_token]
      User.find_by_remember_token(remember_token) unless remember_token.nil?
    end
end

copying it to my static_pages_helper didn’t accomplish anything.

  • 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-05-31T16:12:59+00:00Added an answer on May 31, 2026 at 4:12 pm

    Quick things you should be aware of the rails framework and the ruby language:

    • A function defined in any of your helpers will be available to all helpers and views (so there is no reason to copy and paste the same functions through different helpers);
    • You’re probably using an authentication gem and I guess it is the Devise gem. If this is right, then you should not be overriding their helpers unless you have a reason to do this;
    • User.anything will call the static function anything from the User class;
    • user = User.find_by_anything(the_thing) is a class static helper provided by ActiveModel that will query the database looking for a user that has *anything = the_thing*; this user or nil will be returned;
    • user.an_attribute will call a function that returns the user specified attribute (which is the same as the column name of this attribute by default);
    • user.try(:anything) will try to call the function anything from the user and return its value. If user is nil, the returned value will also be nil.

    That said, I guess you just wanted to retrieve the current user remember token, which can be accomplished with the following:

    user = current_user.try(:remember_token)
    

    EDITED: The question is a bit messy, but I also think the following code will work with your controller:

    def profile
      @user = User.find_by_remember_token(params[:remember_token])
    end
    

    You must access the request’s parameters through the params hash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought these two methods were (memory allocation-wise) equivalent, however, I was seeing out
I thought that by convention, only methods with an exclamation mark altered the object.
I see many methods that specify an interface as return value. Is my thought
I'm not really familiar with creating generic methods, so I thought I'd put this
I often have to implement some interfaces such as IEnumerable<T> in my code. Each
Let's say I have some parameters such as a,b,c, and I need to store
I've been trying to pickle an object which contains references to static class methods.
I'm a new member. I have been struggling with sqlitejdbc, I thought. I made
I have my entities such as Customer, Order etc. defined in my Domain Model.
I always thought that a method parameter with a class type is passed as

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.