Railsでの実装方法の話ですかね?
であれば、いろいろとやり方あると思いますが、imageテーブルが仮にあるとして
rb
1# これは参考情報です
2=> #<Image:0x00007fe2a605b191
3 "id": 201,
4 "filename": "gazou-100maime",
5 "created_at": "2018-01-20 00:00:20",
6 "updated_at": ...
7
8
9# 下記は適宜質問者様の都合の良いModelに読み替えてください
10# 今回の件で言えば、Product Model
11class Image
12 def is_new
13 (3.days.ago..Time.current).cover?(Time.parse(self.created_at))
14 end
15end
このis_newをあとはview側で呼び出してあげるだけです
追記
修正前:
rb
1<% @products.each do |product| %>
2<div class="col-xs-12">
3<%= attachment_image_tag product, :image , class: "product_image" %>
4</div>
5<% end %>
修正後:
rb
1<% @products.each do |product| %>
2 <div class="col-xs-12">
3 <% if product.is_new %>
4 <%= image_tag 'NEW' %>
5 <% end %>
6 <%= attachment_image_tag product, :image , class: "product_image" %>
7 </div>
8<% end %>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/02/12 02:00
2018/02/12 07:01
退会済みユーザー
2018/02/13 13:26
退会済みユーザー
2018/02/13 13:37
2018/02/13 18:16
退会済みユーザー
2018/02/14 11:33 編集
2018/02/14 04:48 編集
退会済みユーザー
2018/02/14 07:06