I''m stumped and could use a little help. I''m not getting a
model to
read session data that I set in a controller. I''ve read up on
sessions but I must still be missing something.
In my app, a user selects an event to attend, is prompted for
attendee information, and the event with the related attendee data is
added to the line items of a shopping cart. The cart is a derivative
of the AgileWDR sample cart. The relevant bits of code are:
class StoreController < ApplicationController
def add_attendee
#produces the form
@event = Product.find(params[:id])
@attendee = @session[:person] ||= Attendee.new
end
def add_event_to_cart #processes
the form
attendee = @session[:person] = Attendee.new(params[:attendee])
@event = Product.find(params[:id])
@cart.add_event(@event)
redirect_to(:action => ''display_cart'')
end
end
class Cart
attr_reader :items
def add_event(event)
@attendee = @session[:person]
item = LineItem.for_product(event)
item.attendees << @attendee
@items << item
end
end
No matter what I try, it gives me a "you have a nil object" when it
reads back in the session variable in Cart.add_event. I can check
and see that the session data is being set correctly. If I force
feed the new Attendee object sample information, the hash looks the
same as the session data and the whole application works fine. So it
seems that it is just getting stuck on reading back in the session
variable.
I should also mention that :person in @session[:person] does not have
a corresponding model. However, I get the same results if I use
@session[:attendee] instead (which does) and require the model using
"model :attendee" in the ApplicationController.
Am I addressing the session variable incorrectly? Is there a better
way to pass form parameters to a model? Or am I doing something else
wrong?
Thanks in advance for any help you can offer!
Kevin Skoglund