Jeremy W. wrote:
ok, so I’m having a little problem here.
here’s the code:
class Admin::RequestFormController < Admin::FrontController
def show
session[:request_form] ||= RequestForm.new
end
def add_showing
@showing = Showing.find(params[:showing_id])
show.add_showing(@showing)
end
end
now, if I go to my view and do <%= debug(session[:request_form]) %>
I actually get what I’m looking for, I can do a logger.debug and get the
request_form object, what I’m not getting is the request_form object
when I ask it to add_showing. I get a nil.add_showing error. Anyone who
can help is much appreciated.
I’m a newbie, but I’ll take a stab at getting you moving again.
I think maybe the unusual “ing” ending of the noun “showing” is lending
some confusion here. Usually one would have model related names with
more ordinary sounding noun forms, like a “Car” model, where a
particular record is a “car”.
I’m thinking maybe your “Showing” model is an active record child, and
your controller method “add_showing” is attempting to create a new
“showing” based on the info typed into the “show” view by a user? If
so, I think it might want to look more like this…
def add_showing
showing = Showing.new(params[:showing])
showing.save
end
This is somewhat oversimplified as normally there would be validation
involved and stuff to tell the user what happened after they attempted
to create a new showing, and perhaps going afterwards to a list of
showings with the new one selected, etc.
Now might be a good time for another quick read through some of the
example chapters in the Agile Rails book. It can take several
iterations back and forth between reading and trying to do some on your
own before it starts to sink in. It did for me, and I’m still
iterating. More than likely I’ve messed this up some and somebody
further along will now chime in and correct me.
hth,
jp