很抱歉重复,经过大量搜索,我无法找到问题的答案。 {_ 1}}调用后,will_paginate无效。
这是控制器代码。
Ajax
这是索引视图:
class CitiesController < ApplicationController
def index
@cities = City.get_cities(params[:city_name],params[:city_population]).paginate(:page => params[:page])
respond_to do |format|
format.html
format.js
end
end
def create
@city = City.new(params[:city])
if @city.save
flash[:success] = "City information saved successfully"
redirect_to cities_path
else
render 'index'
end
end
def new
@city = City.new
end
def destroy
@city = City.find(params[:id]).destroy
@city.destroy
@cities = City.all
respond_to do |format|
format.html {redirect_to cities_path}
format.js
end
end
end
以下是该表的局部视图:
<div class="row">
<h1>Search Cities or <%= link_to "Create New City", new_city_path %></h1>
<h3>99 random city information are generated in the database </h2>
<h3>Simply type any letter or city population between 0 and 10 to filter out</h3>
<%= form_tag "/cities/index", method: :get, remote: true do %>
<%= label_tag(:q, "City Name:") %>
<%= text_field_tag 'city_name' %>
<%= label_tag(:q, "City Population greater than, in units of 1 million:") %>
<%= text_field_tag 'city_population' %>
<label></label>
<%= button_tag("Search", :class => "btn") %>
<% end %>
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>"><%= value %></div>
<% end %>
<div id='table' class="table table-striped">
<%= render 'table' %>
</div>
<%=will_paginate @cities %>
</div>
答案 0 :(得分:1)
自己找到解决方案。
将<%= will_paginate @cities %>
添加到部分文件
并将@cities = City.all
更改为
@cities = City.all.paginate(页面:params [:page])
因为will_paginate
不期望array
个对象。
答案 1 :(得分:0)
写入您的控制器
def index
@cities = City.get_cities(params[:city_name],params[:city_population]).paginate(:page => params[:page])
respond_to do |format|
format.html
format.js
end
end
在您的视图文件夹中创建index.js.erb
并写入
$('id or class').html('<%=escape_javascript render :partial => which part you update %>')