我上传到制作我的页面。在localhost,页面中,运行OK但在生产中在仪表板索引中生成此错误。
乘客错误
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索引视图
<% 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
但是我使用分页将通过页面分页。此分页在仪表板索引中运行正常但没有。我看过一次页面。但是我试着再次进入。产生此错误。
感谢您的建议
答案 0 :(得分:1)
在您的行动中使用此功能:
@movements = current_user.person.saving.movements.paginate :page => params[:page] if current_user.present?
@movements = [] if current_user.blank?
你可能可以摆脱@movements = [] if current_user.blank?
,因为无论如何你都在检查视图中是否存在current_user。
这在你看来:
<% if @movements.length > 0 %>
<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 %>
这是如何运作的?