Search code examples
roda

How to ask if something is .present? in a view in Roda


I am converting a Rails app to Roda. Here's a section of a partial.

# _banner.erb
<% if banner.present? %>
  ...
<% end %>

This returns the error: NoMethodError: undefined method 'present?' for []:Array.

How can I get Roda to support something simple like checking if a variable is present?


Solution

  • All present? does is negate blank? which in turns looks like this. You could add this to your helper/service classes depending on your setup.

    def present?
      !blank?
    end
    
    def blank?
      respond_to?(:empty?) ? !!empty? : !self
    end