我怎样才能显示“明天"?Ruby On Rails 中的日历列表? [英] How can I display "Tomorrow" of calendar list in Ruby On Rails?
本文介绍了我怎样才能显示“明天"?Ruby On Rails 中的日历列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Rails 的新手.
I'm new to Rails.
我尝试创建日历列表,但遇到了一些问题.
I tried to create a calendar list and I encountered some problem.
我是这样做的:
这是我的代码
查看:
<% @start_date.each do |day, posts| %>
<% if day.today? %>
<h4 id="today_title">Today <%= day.strftime("%b %d")%></h4>
<% posts.each do |post| %>
<p class="post_title">。<%= post.title %></p>
<%end%>
<%else%>
<h4 class="other_day_title"><%= day.strftime("%A %b %d") %></h4>
<% posts.each do |post| %>
<p class="post_title">。<%= post.title %></p>
<%end%>
<%end%>
<%end%>
控制器:
def index
@posts = Post.all.order(:start_time)
@date = params[:month] ? Date.parse(params[:month]) : Date.today
@start_date = @posts.group_by {|t| t.start_time.beginning_of_day }
end
同样,我尝试将一些代码设为 <% if day.today?%>
像这样显示明日栏:
Similarly,I try the some code as <% if day.today? %>
to display the tomorrow bar like this:
<% if (day+1).today? %>
<% if day.today+1.day? %>
<% if day.today.next_day? %>
<% if day.tomorrow? %>
但是我得到了一些错误:
But I got the some error :
undefined method `today' for Sun, 07 Feb 2016 00:00:00 UTC +00:00:Time
有答案吗?
感谢阅读:)
推荐答案
你需要使用类似的东西:
You need to use something like:
<% if (day-1.day).to_date.today? %>
<% if day.to_date.eql?(Date.today+1.day) %>
<% if day.to_date.eql?(Date.today.next_day) %>
<% if day.to_date.eql?(Date.tomorrow) %>
这篇关于我怎样才能显示“明天"?Ruby On Rails 中的日历列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文