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 365147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:30:34+00:00 2026-05-12T13:30:34+00:00

When someone visits my train schedule site , he enters a from station, a

  • 0

When someone visits my train schedule site, he enters a “from station”, a “to station”, and then submits the form to get the schedule.

I want the site to remember the user’s last choice of from / to station when he next visits the site. Here’s my current strategy:

In my index action (the action corresponding to the root URL):

def index  
  to_station = "Grand Central Terminal"
  from_station = ""

  if session[:from_station]
    from_station = session[:from_station]
  end
  if session[:to_station]
    to_station = session[:to_station]
  end

  @schedule = Schedule.new(:to_station => to_station, :from_station => from_station)
end

In my show action (the action that shows the actual train schedule):

def show
  @schedule = Schedule.new(params[:schedule])

  if @schedule.trains
    session[:from_station] = @schedule.from_station
    session[:to_station] = @schedule.to_station
    render :partial => 'table', :locals => { :schedule => @schedule }
  else
    render :partial => 'error', :locals => { :schedule => @schedule }
  end
end

And in my ApplicationController:

  session :session_expires => 1.year.from_now

Is this the right approach? In particular, is session :session_expires => 1.year.from_now the “right” way to make the session (and by extension the user’s choice of stations) last for a “long time”?

  • 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-12T13:30:34+00:00Added an answer on May 12, 2026 at 1:30 pm

    You should use cookies

    cookies[:<name>] = { :value => "<value>", :expires => <time of expiry>}
    

    The first reason for this is that storing the data in session means that the data is stored in yuor server’s memory. Eventually, with you keeping that data in memory for such large amounts of time, you memory will get full

    The second reason is that if you need to restart your server (or some something that requires the apache/iis/ror/web hosting service to be restarted) session data will be cleared. Session is typically for short term data storage.

    Now there are such things as SqlSessionStores (eg http://railsexpress.de/blog/articles/2005/12/19/roll-your-own-sql-session-store) so you could store your session data for much longer, without the limitation of server memory filling up and without the limitation of lossing all session data if you restart your server. However be warned that these are still designed for short term storage, I wouldn’t use them for long term storage.

    Cookie – Kept until user clears cookies in browser, or until cookie expires; long term non-critical storage

    Session – Kept until user clears cookies in browser (cookies are used to track a user and identify their session), or web service/server restarts, or session expires; short term non-critical storage

    SqlSession – Kept until user clears cookies in browser, or session expires; short term non-critical storage

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

Sidebar

Related Questions

So anytime someone visits this page: http://www.site.com/page/image_(.*).png They get redirected to the cdn url,
I want it so that if someone visits: http://www.site.com/#hash It puts the data after
When someone visits my page I want them to be rerouted to the login
When someone visits my site via a facebook invite; is there anyway I can
Every time someone visits my site, I show one of three options (A, B,
Does it have to stop itself? What if someone visits my site, starts the
Suppose someone: visits and ASPX page (http get request). sets a too large file
Do the initializers in a Rails app run each time someone visits the site?
Here is the code I use when someone visits a product page on my
how can i detect if someone visits my website using safari or iexplorer via

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.