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"?