There is a table of lessons. In the table there is a field cover. There and put the file name after downloading.

There are N records. I take each record in a loop. In the cycle for the test I wrote it:

<%= lesson.cover %> <br> <%= lesson.cover.present? %> 

In one record uploaded file. In the table, the file name of this record is available. The file on the server is available.

As a result, after going through the cycle, each lesson has 1 empty line (here we are talking about HTML) and one line with false, but one lesson (which has a cover loaded) has this:

 /uploads/lesson/cover/3/b4eef2e86d1c754f.jpg false 

And I do not understand what it is and how it is possible ... In my other project there is exactly the same line - resource.cover.present? but only she works there.

Added by:

Solved the problem by adding .url :

 lesson.cover.url.present? 

But, as I already wrote above, this option works without any problems in my other project:

 resource.cover.present? 

What can be wrong?

    1 answer 1

    If you call lesson.cover, the object of your CarrierWave Uploader is returned. It is more correct to check this way (the link will be returned, and if it is not, then nil):

     lesson.cover_url # вернет nil если картинка отсутствует 

    so it is more correct to check this:

     lesson.cover_url.present?