Use SQL statements to display specific records

An article that writes as a memorandum of what you have discovered through the implementation of the app.

What was stuck this time

I want to display only those that are empty in a specific column in the table

I want to display only those with a specific column in the list, so I first google the description to take that record in the SQL statement. Then

SELECT *FROM table name WHERE column name IS NULL;

Discovered! After checking, it seems that the record targeted by this description has been acquired.

But I can't use this for app implementation

In this case, the tasks are lined up in a list. How can I display only tasks for which the Point column of the tasks table is empty? First, go to check the index


 <% if user_signed_in? %>
    <%= @tasks.each do |task| %>
       <%= link_to edit_task_path(task.id) do %>
           <div class="task" >
           <span class='task-btn'><%= task.content %></span>
           </div>
       <% end%>   
     <% end %>
 <% end %>  

This is a description that is lined up in a list. This @tasks is defined by the controller, so go to see the controller

def index
      if user_signed_in?
      @tasks = Task.all
      end
  end

I think it is necessary to change the description to be assigned in this @task, and I worry about 2 hours. Conclusion

def index 
      if user_signed_in? 
      @tasks = current_user.tasks.where(point: nil)
      end
  end

I was able to display a record with an empty Point on the screen with the description of. I was taught how to specify a condition from the tasks table in user.tasks.where (condition) and display it in a different case before, so I was able to solve it by getting a hint from it.

Recommended Posts

Use SQL statements to display specific records
[Rails] How to use video_tag to display videos
How to use Map
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
PATH to use docker-slim
How to use Twitter4J
How to use active_hash! !!
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
[How to use label]
How to use identity
How to use hashes
How to use JUnit 5
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
I want to use FireBase to display a timeline like Twitter
[Swift] Use UIProgressView to display progress + UIAlertController to notify processing completion