我一直在尝试使用复选框按日期过滤列表。 每个复选框都有一个日期,我想要它,所以当你点击一个复选框时,它会显示整个星期的列表。
#events_controller
def index
@q = Event.ransack(params[:q])
@events = @q.result
@weeks = Semester.current.range.select {|w| w.wday == Semester.current.start_dt.wday}.map(&:to_s)
-
#index.html.erb
<div class="col-10">
<div class="dates ">
<%= search_form_for @q, id: "filters_click", remote: true do |f| %>
<div id="dates">
<% i = 1 %>
<% @weeks.each do |date| %>
<div class="ck-button ">
<label class="d-flex h-100 justify-content-center">
<%= hidden_field_tag :start_dt_lteq, (date.to_date + 7.days) %>
<%= radio_button_tag('q[start_dt_gteq[]', date, nil, class: "date" ) %>
<span class="align-self-center">
Week <br />
<%= i %>
<% i += 1 %>
</span>
</label>
</div>
<% end %>
</div>
<% end %>
</div>
</div>
-
#index.js.erb
$(".events").html('<%= j render @events %>');
-
#events.coffee
$(document).on 'turbolinks:load', ->
$('input:radio').change ->
$("#filters_click").submit();
目前,它会将搜索参数发送回服务器,但结果不会显示在视图中。有什么想法吗?