gpt4 book ai didi

ruby-on-rails - 日期范围不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 16:44:52 24 4
gpt4 key购买 nike

我的应用程序的同一方面有两个问题,抽象 View 是这样的:

该应用程序允许用户查看不同的视频剪辑。在后端/管理部分,管理员可以跟踪任何特定剪辑组的 View 。例如,管理员可以选择 Universal Studios,选择一个 日期范围:开始日期:2015-01-1,结束日期:2016-01-1 并点击 filter,然后查看 Universal 在此范围内收到的总观看次数。

问题是,一方面,datepicker 不再工作,所以当我点击日期字段时,没有出现日历,我必须手动输入日期。对于两个,我只会在进一步的结果之间得到结果:2015-10-182016-02-18。当我输入 2015-09-18 或任何更早的内容时,它不会生成结果。

查看下面的代码,如果您需要任何其他代码,请告诉我!

Index.html.erb 片段:

<tr>
<td><%= f.text_field :start_date, value: 1.month.ago.strftime('%Y-%m-%d') %></td>
<td><%= f.text_field :end_date, value: Time.now.strftime('%Y-%m-%d') %></td>
<td>
<%= f.submit "Filter", class: "btn btn-danger", data: {disable_with: 'Searching...'} %>
<%= link_to 'Clear Form', '#', id: "clear", class: 'btn btn-default' %>
</td>
</tr>

_impressions.html.erb 片段:

    </style>
<div class="clearfix"></div>
<% if @impressions.blank? -%>
<div class="span12"><h1>Nothing found</h1></div>
<% else %>
<div class="alert alert-success">
<div class="">Total Views: <b><%= @impressions.count %></b></div>
<div class="">Percentage to overall views: <b><%= @percentage.round(2) %>%</b></div>
</div>

<table id="table_3" class="table table_output">
<thead>
<tr>
<td class="stat_head">Studio</td>
<td class="stat_head">Film</td>
<td class="stat_head">Clip</td>
<td class="stat_head">User</td>
<td class="stat_head">State</td>
<td class="stat_head">Country</td>
<td class="stat_head">Type</td>
<td class="stat_head">Date</td>
</tr>
</thead>
<tbody>
<% @impressions.each do |impression| -%>
<% @clip = Clip.where(id: impression.impressionable_id).first %>
<% user = User.where(id: impression.user_id).first %>
<tr>
<td><%= link_to @clip.film.studio.name, saas_admin_studio_path(@clip.film.studio) %></td>
<td><%= link_to @clip.film.name, saas_admin_studio_film_path(@clip.film.studio, @clip.film) %></td>
<td><%= link_to @clip.name, saas_admin_studio_film_clips_path(@clip.film.studio ,@clip.film) %></td>
<td><%= user.present? ? (link_to user.username, saas_admin_account_user_path(user.account, user)) : ' - ' %></td>
<td><%= user.present? ? user.account.organization.state : ' - ' %></td>
<td><%= user.present? ? user.account.organization.country_id : ' - ' %></td>
<td><%= user.present? ? user.account.subscription.state : ' - ' %></td>
<td><%= user.present? ? impression.created_at.strftime("%b %e, %Y %l:%M%P") : ' - ' %></td>
</tr>
<% end -%>

最佳答案

你为什么不做这样的事情:

<%=label_tag :start_date, "Start Date" %>
<input id="datepicker" name="someName" ...any other options>

然后:

<script>
$(document).ready(function(){
$("#datepicker").datepicker();
});
</script>

然后当然也为 end_date 添加一个类似的字段。

请注意,您必须在 application.js 中包含 //= require jquery-ui/datepicker

关于ruby-on-rails - 日期范围不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35493222/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com