Session variable data validation

I’ve been using rails for about a month and I’ve been noticing that most
of my controller functions use values from my session variable. I find
that I write something like:

person = Person.find(session[:person]
if( person )

else
flash[:notice] = “unable to retrieve person”
redirect_to( :action => index )
end

It seems redundant to write similar code for every action. I could use
a hook to check the value before each action, but then I would be
accessing my database twice for the same data. Is it overkill to be
making sure something wasn’t deleted out of the database on each action?
How bad is it if my page tries to use an objec that is nil? What is the
standard practice?

Thanks for your help,
Chris

Maybe you can write a private method in your controller that do this
work for you.

Chris Rericha escribió:

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