【发布时间】:2017-07-13 12:42:10
【问题描述】:
我有一个WeekDay 的控制器。然后我尝试在我的项目中添加 RanSack。它工作得很好,除非我尝试启用remote true,它只显示搜索表单。正在进行 AJAX 调用,但没有任何显示。
控制器代码
def index
@q = WeekDay.ransack(params[:q])
@week_days = @q.result().page(params[:page]).per(10)
respond_to do |format|
format.html # index.html.erb
format.json { render json: @week_days }
end
end
index.html.erb
<div id="week_days"><%= render 'week_days' %></div>
_week_days.html.erb
<%= search_form_for @q,remote: true do |f| %>
<%= f.label :datum_gteq %>
<%= f.date_field :datum_gteq%>
<%= f.label :datum_lteq %>
<%= f.date_field :datum_lteq %>
<%= f.submit %>
<% end %>
<table>
<thead>
<tr>
<th><%=sort_link @q, :datum %></th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @week_days.each do |week_day| %>
<tr>
<td><%= l week_day.datum %></td>
<td><%= link_to 'Show', week_day %></td>
<td><%= link_to 'Edit', edit_week_day_path(week_day) %></td>
</tr>
<% end %>
</tbody>
</table>
<%= paginate @week_days %>
<br>
<%= link_to 'New Week Day', new_week_day_path %>
【问题讨论】:
-
改进的语法和代码格式。删除了 404 错误的要点链接。
标签: ruby-on-rails ruby ajax pagination