Search code examples
ruby-on-railsrubysinatra

Ruby how to get array with boolean?


i would like to get a arrau of boats, but i would like that just show the boats with rent boolean set to true.

how can acomplish this?

i've added:

@boats = Boat.where(rent: true)

But did not worked

i even tried the method model

def rents
    self.class.where(rent: true)
  end

and did not worked either


Solution

  • You can do something like this

    <% @boats.where(:rent=>true).each do |t| %> 
     <%= t.name %>
    <%end%>
    <%= @boats.where(:rent=>true).all %>
    

    or

    <% if boats.where(:rent=>true).exists?  %>
     <%= t.name %>
    <%end%>
    

    or

    def rents
     @boats.where(:rent=>true).all
    end