Nil objects

Hello guys,

I am an old PHP guy. I have been using rails for a few months now. One
thing i have never udnerstood about rails is the way it handles nil

I have a form that can be used to insert data. The same form can also be
used to edit data. This edit data is stored in a session.

When a user fills out the form and clicks submit a new record is created
in the database and its also stored in the session. The user is then
taken to another form.

If the user clicks back to go the first form i wish for the data that
was just filled out to appear. That works fine if i do something liek

<%= text_field("details", "name", "size" => 40, :value => session[:exhibition].name ) %>

However with the above code i get a nil object error if the session is
not alreay set. How can i get around this? Is there a way to make rails
ignore the nil object and just output nothing like php does?

you can try two ways.

In controller,

unless session[:exhibition]

enters this block when session is nil and u can assign it here



Give a condition before the text_field
In view,

<% if !(session[:exhibition].nil?)%>
<%=text field… %>