當有人訪問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