Filters

Hi,

How I do a filter in a block of code?

example:

I have a block:

<% @notes[(0…3)].each do |note| %>

  • <%= notes.note %>

    <%= notes.type %>

  • <% end %>

    Type is a string, I would like to do a block filtering by a value on type.

    Thanks!

    Hi Fernando,

    Hi, How I do a filter in a block of code? example: I have a block: <% @notes[(0..3)].each do |note| %>

           <% if notes.type.class == String %>

          &lt;li&gt;
            &lt;%= notes\.note %&gt;
            &lt;%= notes\.type %&gt;
          &lt;/li&gt;
    

          <% end %>

    <% end %> Type is a string, I would like to do a block filtering by a value on type.

    However, your code will be much more testable if you do the filtering on @notes in the controller, or even better, by writing a method in your model that only returns records with type of class String.

    HTH, Bill

    Thanks by the tip!