On 28 May 2011 18:21, David Kahn <d...@structuralartistry.com> wrote:
> I am also wondering if there is a better way to achieve what you want

At the risk of hijacking the thread, I'd be happy to know of any
better ways that can be suggested to achieve this. For example, I've
got this method (okay, it's a get rather than set, but it's the same
idea):

  alias_method :ar_creator, :creator
  def creator
     ar_creator || Person.find_by_sql("select 'unknown' as firstname,
'noter' as lastname, '' as othernames").first
  end

I *could* check for the existence of "creator" [1] in views and other
places, but it sometimes strikes me as easier to just ensure I'm
providing a valid associated object from the model if one does not
exist.


[1] I do use guards most of the time, but on occasion, the amount of
checks for "if Model.associated_object" seems not very DRY

-- 
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to