2009/9/28 Cs Webgrl <[email protected]>:
>
> Hi,
>
> I have a model property with has_many.  I find the property and then I
> need to find the name of the building or the neighborhood that the
> property belongs to.  The property is not always assigned a building or
> neighborhood.
>
> This becomes a problem when createing permalinks with permalink_fu.
>
> has_permalink [:neighborhood_name, :building_name, :address]
>
> The neighborhood name and building name are defined here in property.rb
>
>  def neighborhood_name
>      neighborhood.name
>  end
>
>  def building_name
>       building.name
>  end
>
> If the property does not have a neighborhood or a building, then I get
> an error:
> The error occurred while evaluating nil.name):
>  app/models/property.rb:425:in `neighborhood_name'
>
>
> I know that I'm missing something really basic in Rails.  Can someone
> help me out so that it generates the permalink even if the neighborhood
> or building are empty?
>

You could just test neighborhood and building in your _name methods
and return an appropriate default if nil.

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to