生产中分页的问题
我将我的页面上传到生产环境。在 localhost 页面中运行正常,但在生产中会在仪表板索引中产生此错误。
乘客错误
Processing DashboardController#index (for 190.19.21.199 at 2011-03-04 06:00:27) [GET]
Parameters: {"action"=>"index", "controller"=>"dashboard"}
NoMethodError (undefined method `to_i' for {:page=>nil}:Hash):
searchlogic (2.4.19) lib/searchlogic/active_record/association_proxy.rb:14:in `send'
app/controllers/dashboard_controller.rb:6:in `index'
passenger (3.0.0) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
passenger (3.0.0) lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
passenger (3.0.0) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:321:in `start_request_handler'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `send'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `handle_spawn_application'
passenger (3.0.0) lib/phusion_passenger/utils.rb:479:in `safe_fork'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:270:in `handle_spawn_application'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:357:in `__send__'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:180:in `start'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:149:in `start'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:219:in `spawn_rails_application'
passenger (3.0.0) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:214:in `spawn_rails_application'
passenger (3.0.0) lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize'
passenger (3.0.0) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:213:in `spawn_rails_application'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:132:in `spawn_application'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:357:in `__send__'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.0) helper-scripts/passenger-spawn-server:99
仪表板索引视图
<% content_for :header do -%>
<% unless current_user.nil? %>
Mi Cuenta
<% else %>
Ingrese al sistema
<% end %>
<% end -%>
<% unless current_user.nil? %>
<% unless @movements.blank? %>
<h2>Balance</h2>
<%= get_total_balance(current_user) %>
<h2>Ultimos movimientos</h2>
<table>
<th>Fecha</th>
<th>Debite</th>
<th>Acredite</th>
<th>Total</th>
<% @movements.each do |m| %>
<tr>
<td><%= m.date.to_date %></td>
<td><%= m.debit %></td>
<td><%= m.credit %></td>
<td><%= m.balance %></td>
</tr>
<% end %>
</table>
<%= will_paginate @movements %>
<% else %>
No hay movimientos para mostrar
<% end %>
<% else %>
<div style="width: 40%; margin: 0 auto;">
<%= render :partial => 'sessions/new' %>
</div>
<% end %>
索引控制器
def index
@movements = current_user.person.saving.movements.paginate :page => params[:page] || 1 unless current_user.nil? || current_user.person.saving.movements.blank?
end
但是我使用分页将通过页面分页。此分页运行正常,但仪表板索引中没有。我看过该页面一次。不过我尝试再次进入。产生这个错误。
谢谢指教
I upload to production my page. In localhost, the page, run OK but in Production produce this error in dashboard index.
Passenger error
Processing DashboardController#index (for 190.19.21.199 at 2011-03-04 06:00:27) [GET]
Parameters: {"action"=>"index", "controller"=>"dashboard"}
NoMethodError (undefined method `to_i' for {:page=>nil}:Hash):
searchlogic (2.4.19) lib/searchlogic/active_record/association_proxy.rb:14:in `send'
app/controllers/dashboard_controller.rb:6:in `index'
passenger (3.0.0) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
passenger (3.0.0) lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
passenger (3.0.0) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:321:in `start_request_handler'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `send'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `handle_spawn_application'
passenger (3.0.0) lib/phusion_passenger/utils.rb:479:in `safe_fork'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:270:in `handle_spawn_application'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:357:in `__send__'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:180:in `start'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:149:in `start'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:219:in `spawn_rails_application'
passenger (3.0.0) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:214:in `spawn_rails_application'
passenger (3.0.0) lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize'
passenger (3.0.0) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:213:in `spawn_rails_application'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:132:in `spawn_application'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:357:in `__send__'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.0) helper-scripts/passenger-spawn-server:99
DAshboard Index view
<% content_for :header do -%>
<% unless current_user.nil? %>
Mi Cuenta
<% else %>
Ingrese al sistema
<% end %>
<% end -%>
<% unless current_user.nil? %>
<% unless @movements.blank? %>
<h2>Balance</h2>
<%= get_total_balance(current_user) %>
<h2>Ultimos movimientos</h2>
<table>
<th>Fecha</th>
<th>Debite</th>
<th>Acredite</th>
<th>Total</th>
<% @movements.each do |m| %>
<tr>
<td><%= m.date.to_date %></td>
<td><%= m.debit %></td>
<td><%= m.credit %></td>
<td><%= m.balance %></td>
</tr>
<% end %>
</table>
<%= will_paginate @movements %>
<% else %>
No hay movimientos para mostrar
<% end %>
<% else %>
<div style="width: 40%; margin: 0 auto;">
<%= render :partial => 'sessions/new' %>
</div>
<% end %>
index controller
def index
@movements = current_user.person.saving.movements.paginate :page => params[:page] || 1 unless current_user.nil? || current_user.person.saving.movements.blank?
end
However I use pagination with will paginate through the page. This pagination run OK but no in dashboard index. I see the page once. however i tried to enter again. Produce this error.
Thanks in advice
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的操作中使用它:
您可能可以摆脱
@movements = [] if current_user.blank?
因为您无论如何都在检查视图中是否存在 current_user 。在您看来:
这是如何运作的?
Use this in your action:
You can probably get rid of
@movements = [] if current_user.blank?
since you are checking for the existence of current_user in your view anyway.And this in your view:
How does that work?