@Joshua - FYI self[:caption] <=> read_attribute(:caption)

@Chris - ...and I am guessing interchangeable with self.caption

On Oct 9, 5:27 am, Chris <c.bartl...@paradise.net.nz> wrote:
> def caption
>   self[:caption] || title
> end
>
> On Oct 8, 5:11 am, Joshua Muheim <rails-mailing-l...@andreas-s.net>
> wrote:
>
> > Hi all
>
> > Oh my god, this really shouldn't be a tough one, but I just don't get
> > it. ;-)
>
> > class Page < ActiveRecord::Base
> >   def caption
> >     caption ? caption : title
> >   end
> > end
>
> > I want to return the content of the title column when the caption column
> > is empty:
>
> > p.caption # Caption is not empty
> > # => "caption"
>
> > p.caption # Caption is empty
> > # => "title"
>
> > Not astonishing, I get a StackLevelTooDeep Exception with my "solution"
> > above... But how can I do it right?
>
> > Thanks a lot... My brain is just a bit wrecked today...
> > Josh
> > --
> > Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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