【问题标题】:date range not working日期范围不起作用
【发布时间】:2016-02-18 21:55:50
【问题描述】:

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

该应用程序允许用户查看不同的视频剪辑。在后端/管理部分,管理员可以跟踪任何特定剪辑组的视图。例如,管理员可以选择Universal Studios,选择date range: Beginning Date: 2015-01-1, End Date: 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 -%>

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 datepicker


    【解决方案1】:

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

    <%=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

    【讨论】:

    • 好的,谢谢。有没有修复我现有代码的解决方案?因为在某一时刻,它确实奏效了。
    猜你喜欢
    • 2015-02-15
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 2013-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多