生产中分页的问题

发布于 2024-10-20 11:22:27 字数 4313 浏览 2 评论 0原文

我将我的页面上传到生产环境。在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魄砕の薆 2024-10-27 11:22:27

在您的操作中使用它:

@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 %>

这是如何运作的?

Use this in your action:

@movements = current_user.person.saving.movements.paginate :page => params[:page] if current_user.present?
@movements = [] if current_user.blank?

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:

<% 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 %>

How does that work?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文