Showing posts only created when boolean was true

60 views Asked by At

Lets say I have one two booleans and two integers. The two booleans behave as radio buttons. What I want to happen is to show all posts made when one boolean was true, and show all when the other was true. (I am new to ruby) and all I have is this <% @tests.each do |test| %> <% if test.type1 == true %> not sure how to show the separate variables

1

There are 1 answers

0
ConnorCMcKee On

I believe what you're saying is you've got the logic down for showing these records, but you need to display the fields themselves. As such my answer will reflect this understanding.

If you're trying to display a record, you only really need to worry about HTML. This is from the Rails Guide:

  <p>
    <%= f.label :title %><br>
    <%= f.text_field :title %>
  </p>

  <p>
    <%= f.label :text %><br>
    <%= f.text_area :text %>
  </p>

  <p>
    <%= f.submit %>
  </p>

All you have to do is arrange the HTML in a way you like, and insert your variables. Ruby data is added to an html.erb filve with <%= ... %>. Whatever the result of the code contained therein is inserted into the html. So if I want to display an integer from the object, I would just write <%= test.my_integer_1 %>, and it would be the same as me simply typing that number into the html. Thus, if I wanted it to display as a header, I would instead type:

<h1>
  <%= test.my_integer_1 %>
</h1>