Session help

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.

On Nov 08, 2006, at 21:38 , Jeremy W. wrote:

def add_showing
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.

This doesn’t appear to be session related.

It appears that show is not defined anywhere in the code and hence
will be nil.

~Wayne

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

Sorry everyone, I was kind of in a rush when I made the post. This
application I am working on is very huge. now in the
def add_showing
@showing = Showing.find(params[:showing_id])
show.add_showing(@showing)
end

section, where I have show, you can change that to just
session[:reques_form].add_showing(@showing) and it will still give me
nil.add_showing error, BUT, if you take off the .add_showing(@showing)
it will work. The object is no longer nil. Now this is only one small
snippet of a lot of other controllers and models working together, so I
know I have everything defined correctly. I thought it might have to do
with add_showing, but the kicker is that add_showing works in console.
all tests have run on all the methods and they all pass. If anyone knows
of anything with session that might be a little trick, glitch, flaw, or
something else that’s weird. Thanks for all the ideas.

~Jeremy

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs