On Jul 21, 2009, at 7:18 AM, Cs Webgrl wrote:

>
> I have done many variations of this code.  Essentially I want this  
> to be
> true.
>
>
> assert_equal '', Org.field_for(nil).display

You've overridden it so I doubt this is the problem, but display is a  
built-in method at a very basic level (somewhere near inspect) so  
maybe that's messing you up in case you aren't overriding it correctly.

> This is a polymorphic relationship.
>
> fieldable.rb
> ============
>
> def field_for(purpose)
>  self.fields.find(
>   :first,
>   :conditions => ["purpose LIKE ?", "#{purpose}"],

Are you sure you didn't mean ["purpose LIKE ?", purpose]  There's no  
reason to quote the second argument.  Although I don't know what Rails  
does when you pass in nil to conditions like that.  Maybe it doesn't  
like that.


>   :order => 'position asc')
> end # def
>
>
>
> field.rb
> ========
> def display
> str = ""
> field.to_s unless search.blank?
> str
> end
>
>
> Can someone help tell me what I'm doing wrong and why I can't  
> produce an
> empty string?  I had thought that nil.to_s created an empty string,  
> but
> just writing the following didn't work either.

It does.

 >> nil.to_s
=> ""

So, something else is wrong somewhere...

>
> def display
>  field.to_s
> end
>
>
> Thanks!
> -- 
> Posted via http://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 [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