我正在尝试使用简单的日历gem在我的应用中生成简单的日历。我有项目模型,其中包含project_title,client_name,description,startdate和enddate。
当我打开项目视图时,我需要显示从startdate到enddate的日历视图。我可以这样做吗?
以下是代码:
<p>
<strong>Project title:</strong>
<%= @project.project_title %>
</p>
<p>
<strong>Client name:</strong>
<%= @project.client_name %>
</p>
<p>
<strong>Project desc:</strong>
<%= @project.project_desc %>
</p>
<p>
<strong>Project startdate:</strong>
<%= @project.project_startdate %>
</p>
<p>
<strong>Project enddate:</strong>
<%= @project.project_enddate %>
</p>
### here i need to get the calendar view from above startdate and enddate
答案 0 :(得分:1)
首先获取:start_date
&amp;之间的差异end_date
:
total_days = end_date - start_date
现在通过传递一些参数来创建自定义日历:
<%= calendar number_of_days: total_days, start_date: start_date_of_your_project do |date| %>
<%= date %>
<% end %>
让我知道!感谢
答案 1 :(得分:1)
你也可以试试这个!
<%= calendar @project.project_startdate..@project.project_enddate do |date| %>
<%= date %>
<% end %>