L
L
lavezzi12015-09-02 17:37:05
Ruby on Rails
lavezzi1, 2015-09-02 17:37:05

How to search for information for output by condition?

Hello. There are articles, table Articles. It has a finished column with a default value of nill. On one page you need to display unread articles, and on the other read. I try to do so

@read = Book.where(finished: 'true', user_id: current_user)

- unless @read.blank?
      - @read.each do |article|
        .book
          .cover
            = some code
          .content
            %h4.title= link_to article.title, article
            %small By #{article.author}
            .description
              %p= article.description
            .date
              Added: #{time_ago_in_words(article.created_at)} ago
    - else
      %p.center It appears you havent't read any article yet.

In console
Article Load (0.2ms)  SELECT "articles".* FROM "articles" WHERE "articles"."finished" = ? AND "articles"."user_id" = 1  

There are no errors, but there are no articles with true either, although in the database I specifically changed the value to true for half of the articles. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2015-09-02
@lavezzi1

Well, isn't it obvious that you have 'true' there - a string, and in the database, most likely - a logical

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question