当有人访问my train schedule site时,他输入“from station”,“to station”,然后提交表单以获取计划。如何在会话中存储简单的用户首选项
我希望网站在下次访问该网站时记住用户上/从站的最后选择。这是我目前的策略:
在我index
行动(对应到根网址的动作):
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
在我show
动作(动作,显示实际列车时刻表):
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
在我ApplicationController
:
session :session_expires => 1.year.from_now
这是正确的方法吗?尤其是,session :session_expires => 1.year.from_now
是“正确”的方式来使会话(以及延长用户选择的电台)持续“长时间”吗?
你怎么得到按钮来改变颜色? – Gutzofter 2009-09-21 03:09:46
@Gutzofter - 我不确定你的意思是 – 2009-09-21 03:30:17
你使用悬停在你的CSS文件? – Gutzofter 2009-09-22 00:42:36