On Wed, Dec 3, 2008 at 5:22 PM, Martyn Elmy-liddiard <
[EMAIL PROTECTED]> wrote:

>
> mahmoud said wrote:
> > On Wed, Dec 3, 2008 at 4:30 PM, Martyn Elmy-liddiard <
> > [EMAIL PROTECTED]> wrote:
> >
> >> Thanks Fred but I still get an error:-
> >> .......etc
> >>
> >>
> >> and the error I get is:-
> >>
> >> You have a nil object when you didn't expect it!
> >> The error occured while evaluating nil.year
> >> --
> >
> >
> > That's because @risks.LastReviewed is the one that is nil
> > use
> > <option value="<%= @risks.LastReviewed.year if @risks.LastReviewed%>"
> > selected="selected">
> >
> >
> > --
> > Mahmoud Said
> > Software Developer
> > blog.modsaid.com
> > www.eSpace.com.eg
> > +20-16-1223857
>
> Mahmoud,
>
> Still not quite seeing why @risks.LastReviewed can be checked for
> existance but @risks.LastReviewed.year cant be. I would have thought an
> element of the date would be able to be checked in the same way as the
> whole date.


In [EMAIL PROTECTED] you are calling the *year* method of the *
@risks.LastReviewed* object which, I assume, is of class *Time*    . if that
object is nil then it is no longer a Time object... it is a nil object of
type NilClass <http://www.ruby-doc.org/core/classes/NilClass.html> .. and
you can only call NilClass methods for it.





>
>
> Anyhow...you help was great and has allowed me to sort the problem so
> thanks very much indeed.
>
> Just for anyone else....I also needed to put the existance check in the
> displayed element of the drop-down selection thus:-
>
> <option value="<%= @risks.LastReviewed.year if @risks.LastReviewed%>"
> selected="selected"><%= @risks.LastReviewed.year if
> @risks.LastReviewed%></option>
>
> Martyn
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>


-- 
Mahmoud Said
Software Developer
blog.modsaid.com
www.eSpace.com.eg
+20-16-1223857

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to