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

79 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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