2009/9/28 Cs Webgrl <[email protected]>:
>
> Colin Law wrote:
>
>> You could just test neighborhood and building in your _name methods
>> and return an appropriate default if nil.
>
>
> Thanks for your reply. I don't mean to make you do all of the work, but
> I can't seem to find the correct syntax to go with this to make it pass
> correctly? Everything I put into the _name methods is ignored and I
> still get an error.
You have snipped the original.
I don't know whether has_permalink is happy with nil parameters, if so
then you could just do
def neighborhood_name
neighborhood.name if neighborhood
end
This will return nil if neighborhood is nil.
If you need a default name however then something like
def neighborhood_name
neighborhood ? neighborhood.name : 'default_name'
end
If Marnen reads this he will tell you (and probably me) in no
uncertain terms to read up on basic Ruby coding :)
Colin
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---