jeudi 19 novembre 2020

Variable, column, check if column input exists with if statement, Ruby on Rails

I am new to Ruby on Rails and I have the following problem. I use partial to put content in specific parts of the website depending on answer given in the form. In other words users can submit 'mediatype', which is a column assigned to 'post' variable. Either they can check it in the form as 'video', 'photo' or 'memo'.

I want to print content if mediatype == memo in one part of the website and another content if mediatype == video and photo, in another part of the website. I assume that I have to use if statment. I am trying something like this in the index page. It should show all posts, where memo == 'Memo'. It does not work. I get error 'undefined method mediatype'. Can you help? Thank you.

<% if @posts.mediatype.include? 'Memo' %>

<% @posts.each do |post| %>
  <tr>
    <td><%= post.title %></td>
  </tr>
  <tr>
    <td><%= post.body %></td>
  </tr>
  <tr>
    <td><%= post.url %></td>
  </tr>
 <% end %>

<% else %>
<% end %>

Aucun commentaire:

Enregistrer un commentaire