Kaminari ajax,它不起作用,rails 3.1 和 Mongoid
我正在关注 https://github.com/amatsuda/kaminari_example/commits/ajax 。我正在使用 kaminari 0.12.4。 (我检查过 0.13.0 并且不起作用)。没有ajax也能正常工作。
我在 users_helper.rb 中有
module UsersHelper
def link_to_next_page(scope, name, options = {}, &block)
param_name = options.delete(:param_name) || Kaminari.config.param_name
link_to_unless scope.last_page?, name, {param_name => (scope.current_page + 1)}, options.merge(:rel => 'next') do
block.call if block
end
end
end
我的 users_controller 下一个方法:
def followers
@user = User.find(params[:user])
@followers = @user.followers_by_type("user")
@followers = Kaminari.paginate_array(@followers).page(params[:page]).per(1)
respond_to do |format|
format.js
format.html { render :layout => 'panel'}# followers.html.erb
format.json { render json: @followers }
end
我在我的 follower.index.html.erb 中有下一个:
<%= render 'followers' %>
<div id="paginator">
<%= link_to_next_page @followers, 'Next Page', :remote => true, :url => { :controller => "users", :action => "followers"} do %>
<span>No More Pages</span>
<% end %>
</div>
我有部分 _followers.html.erb
<% for followers in @followers%>
<div class="followers">
<%= followers.username %>
</div>
<% end %>
我有 followers.js.erb
//$('#box').html('<%= escape_javascript render(:partial => 'followers') %>');
//$('#box #paginator').html('<%= escape_javascript(paginate(@followers, :remote => true).to_s) %>');
alert ('I am follower.js.erb file');
我必须看到一个警报,但没有看到。警报在哪里? :O。文件index.js.erb 没有得到任何东西。问题出在哪里?
在我的日志中,js.erb 工作正常:
Started GET "/maserranocaceres/followers?page=2" for 127.0.0.1 at 2012-01-31 05:26:44 -0800
Processing by UsersController#followers as JS
Parameters: {"page"=>"2", "user_id"=>"maserranocaceres"}
Rendered users/_followers.html.erb (1.1ms)
Rendered users/followers.html.erb (28.7ms)
Completed 200 OK in 38ms (Views: 34.5ms | Solr: 0.0ms)
I'm following https://github.com/amatsuda/kaminari_example/commits/ajax. I'm using kaminari 0.12.4. (I had check with 0.13.0 and and does not work). Without ajax does works fine.
I have in users_helper.rb
module UsersHelper
def link_to_next_page(scope, name, options = {}, &block)
param_name = options.delete(:param_name) || Kaminari.config.param_name
link_to_unless scope.last_page?, name, {param_name => (scope.current_page + 1)}, options.merge(:rel => 'next') do
block.call if block
end
end
end
I have in my users_controller the next method:
def followers
@user = User.find(params[:user])
@followers = @user.followers_by_type("user")
@followers = Kaminari.paginate_array(@followers).page(params[:page]).per(1)
respond_to do |format|
format.js
format.html { render :layout => 'panel'}# followers.html.erb
format.json { render json: @followers }
end
I have in my follower.index.html.erb the next:
<%= render 'followers' %>
<div id="paginator">
<%= link_to_next_page @followers, 'Next Page', :remote => true, :url => { :controller => "users", :action => "followers"} do %>
<span>No More Pages</span>
<% end %>
</div>
I have in partial _followers.html.erb
<% for followers in @followers%>
<div class="followers">
<%= followers.username %>
</div>
<% end %>
I have in followers.js.erb
//$('#box').html('<%= escape_javascript render(:partial => 'followers') %>');
//$('#box #paginator').html('<%= escape_javascript(paginate(@followers, :remote => true).to_s) %>');
alert ('I am follower.js.erb file');
I have to see a one alert but not seen. Where is the alert? :O. The file index.js.erb does not gets nothing. Where is the problem?
In my log appear working fine the js.erb:
Started GET "/maserranocaceres/followers?page=2" for 127.0.0.1 at 2012-01-31 05:26:44 -0800
Processing by UsersController#followers as JS
Parameters: {"page"=>"2", "user_id"=>"maserranocaceres"}
Rendered users/_followers.html.erb (1.1ms)
Rendered users/followers.html.erb (28.7ms)
Completed 200 OK in 38ms (Views: 34.5ms | Solr: 0.0ms)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能听起来是一个愚蠢的建议,但我过去遇到过这样的问题,更改格式的顺序会有所帮助,请尝试:
it might sound a silly suggestion, but i have had issues like this in the past where changing the order of the formats helps, try: