How can I treat important session info as if it were a model?
I've started toying with it, and some of it works. But I'm not sure what I'm missing? Does anyone know a good place to start or where I can find some good examples?
Also, I'm able to use the model to set session variables, but what about getting them from the model as opposed to always using session[:blah]... How can I retrieve them from the model instead?
class Cart
attr_reader :items
def initialize(session)
@session = session
@session[:cart] ||= []
@items ||= session[:cart]
end
def add_rooms(new_rooms,startdate,days)
#remove 0 values
new_rooms.delete_if {|k, v| v == "0" }
rooms = []
new_rooms.each do |k, v|
#rname = Room.find(k)
#night = Available.find_by_room_id(k)
rooms << {:room_id => k, :people => v, :no_days => days, :startdate => startdate}
end
@session[:cart] = rooms
#@items = rooms
end
end