her icon indicating copy to clipboard operation
her copied to clipboard

blank? returns false for a nested resource that is null

Open dim882 opened this issue 12 years ago • 2 comments

I'm just getting started with her, so let me know if I'm simply doing it wrong. When a nested resource is null, I'd expect blank? to return true but it returns false.

Here's a stripped down version of my code and the resource:

class Thing
  include Her::Model

  has_one :photo
end

class Photo
  include Her::Model
end

...

[
    
{
        id: 1,
        name: "Something",
        photo: null
    },
    {
        id: 2,
        name: "Something else",
        photo: {
            id: 101,
            url: "http://example.com/image.png"
        }
    }
]

...

things = Thing.all()
things[1].photo.url # =>  "http://example.com/image.png"
things[0].photo.blank? # => false
things[0].photo.url # => NoMethodError: undefined method `empty?' for nil:NilClass

Is this a bug or do I have my models set up incorrectly? Thanks.

dim882 avatar Oct 22 '13 19:10 dim882

You can use photo? to test if the object is present.

vic avatar Nov 10 '13 06:11 vic

This same issue got me today. Is this intended functionality, or a bug? This behavior is different from the default rails behavior.

mculp avatar Apr 02 '14 19:04 mculp