Ruby on rails Rails:Will_paginate在AJAX调用后无法正常工作
对不起,重复了一遍,经过多次搜索,我找不到问题的答案。调用Ruby on rails Rails:Will_paginate在AJAX调用后无法正常工作,ruby-on-rails,ajax,will-paginate,Ruby On Rails,Ajax,Will Paginate,对不起,重复了一遍,经过多次搜索,我找不到问题的答案。调用Ajax后,将分页不起作用 删除操作之后,它根本不显示页码(它只是返回所有结果) 在搜索操作之后,页码不会更新,它显示的页面比实际存在的页面多 这是控制器代码 class CitiesController < ApplicationController def index @cities = City.get_cities(params[:city_name],params[:city_population]).pag
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
class CitiesControllerparams[:page])
回应待办事项|格式|
format.html
format.js
结束
结束
def创建
@城市=城市。新建(参数[:城市])
如果@city.save
flash[:success]=“城市信息保存成功”
重定向到城市路径
其他的
呈现“索引”
结束
结束
def新
@city=city.new
结束
def销毁
@city=city.find(params[:id]).destroy
@城市毁灭
@城市
回应待办事项|格式|
format.html{重定向到城市路径}
format.js
结束
结束
结束
以下是索引视图:
<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>
搜索城市或
数据库中生成99个随机城市信息
只需键入0到10之间的任意字母或城市人口即可过滤掉
“btn”)%%>
以下是该表的局部视图:
<div class="row">
<h1>Enter City descriptions or <%= link_to "Search Cities", cities_path %></h1>
<%= form_for @city, html: {multipart: true} do |f| %>
<%= f.label :city_name %>
<%= f.text_field :city_name %>
<%= f.label :city_description %>
<%= f.text_field :city_description %>
<%= f.label :city_population_in_units_of_millions %>
<%= f.text_field :city_population %>
<label></label>
<%= f.file_field :image%>
<label></label>
<%= f.submit "Create new City", :class => "btn"%>
<% end %>
</div>
Finally two js.erb codes associated with index and delete actions:
index.js.erb:
$('#table').html('<%= escape_javascript(render('table')) %>');
destroy.js.erb:
$('#table').html('<%= escape_javascript(render('table')) %>');
输入城市描述或
“btn”%>
最后,与索引和删除操作关联的两个js.erb代码:
index.js.erb:
$('#table').html('');
destroy.js.erb:
$('#table').html('');
在控制器中写入
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 %>')
$('id或class').html('which part you update%>'))
在控制器中写入
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 %>')
$('id或class').html('which part you update%>'))
我自己找到了解决方案
将
添加到部分文件中
并将@cities=City.all
更改为
@cities=City.all.paginate(第页:参数[:第页])
因为
将分页
不需要对象的数组
我自己找到了解决办法
将
添加到部分文件中
并将@cities=City.all
更改为
@cities=City.all.paginate(第页:参数[:第页])
因为
将分页
不需要对象的数组
谢谢你的回答。我试过了,结果和以前一样。ajax可以工作。问题仍然存在,因为will_paginate根本没有更新……。感谢您的回答。我试过了,结果和以前一样。ajax可以工作。该问题仍然存在,因为will_paginate根本没有更新。。。。。。。。