为什么在我部署的代码上单击特定链接时会出现500错误?

时间:2018-10-19 17:20:40

标签: ruby-on-rails ruby vps cancancan

当我在远程服务器上运行的应用程序中命中特定端点时,我收到500内部错误。是的,代码在我的本地系统/服务器上正常工作。

代码:

order_controller.rb

module Admin
  module Statistic
    class OrdersController < BaseController
      def show
        @orders_grid = ::Statistic::OrdersGrid.new(params[:statistic_orders_grid])
        @assets = @orders_grid.assets
        @paginated_assets = @assets.page(params[:page]).per(20)

        fee_sums_per_currency = {}
        @assets.each do |order|
          fee_currency = order.get_order_fee_currency
          unless fee_sums_per_currency.key?(fee_currency)
            fee_sums_per_currency[fee_currency] = 0
          end
          fee_sums_per_currency[fee_currency] += order.fee
        end
        fee_summary = []
        fee_sums_per_currency.each do |currency, fee_sum|
          fee_summary << "#{ currency } #{ fee_sum }"
        end

        @summary = {
          :count => @assets.length,
          :fee_summary => fee_summary.join(",  ")
        }
        @order_reset_button = true
      end
    end
  end
end

视图/admin/statistic/orders/show.html.slim

.row
  = render "admin/statistic/shared/filter_panel", form_target: @orders_grid, url: admin_statistic_orders_path
.row
  = render "admin/statistic/shared/summary_panel", groups: @assets

.row
  .panel.panel-primary
    .panel-heading
      span = t('admin_header.orders')
    .panel-body
      = datagrid_table(@orders_grid, @paginated_assets)

共享文件

admin / statistic / shared / filter_panel

.panel.panel-primary
  .panel-heading
    h4.panel-title = t('admin.statistic.filter')

  .panel-body
    = form_for form_target, url: url, html: {method: :get, class: 'form-horizontal'} do |f|
      .row
        .col.col-xs-3
          = f.datagrid_label :currency
          = f.datagrid_filter :currency, class: "form-control"
        .col.col-xs-3
          = f.datagrid_label :state
          = f.datagrid_filter :state, class: "form-control"
        .col.col-xs-3
          = f.datagrid_label :type
          = f.datagrid_filter :type, class: "form-control"
        .col.col-xs-6
          = f.datagrid_label :created_at
          .form-inline
            = f.datagrid_filter :created_at, class: "form-control"
        .col.col-xs-2
          br.heighten-br
          = f.submit t('datagrid.form.submit'), class: "btn btn-primary", style: "width: 100%"
        .col.col-xs-2
          br.heighten-br
          = link_to t('datagrid.form.clear'), {:controller => 'admin/statistic/orders', :action => 'show'}, class: 'btn btn-primary', style: "width: 100%"

管理员/统计/共享/ summary_panel

.panel.panel-default
  .panel-heading
    h4.panel-title.row
      a data-parent="#filter-accordion" data-toggle="collapse" href="#summary"
        span.col-xs-8.text-muted = t('admin.statistic.summary')
        span.col-xs-4.text-right.text-muted = t('admin.statistic.click-to-expand')
  #summary.panel-collapse.collapse
    .panel-body
      .datagrid-groups
        - if groups
          - groups.each do |key, val|
            .datagrid.group.row
              span.col-xs-2.title = t("admin.statistic.#{controller_name}.#{controller.action_name}.#{key}")
              span.col-xs-10.value = val

导航栏 基于cancancan

- if can? :menu, Trade
            li.dropdown class = check_active('withdraws')
              = link_to 'javascript:;', class: 'dropdown-toggle', 'data-toggle' => 'dropdown' do
                span = t('admin_header.trades')
                span.caret
              ul.dropdown-menu
                - if can? :manage, Order
                  li class = check_active('orders')
                    = link_to t(".menus.items.operating.orders"), admin_statistic_orders_path

ability.rb

module Admin
  class Ability
    include CanCan::Ability

    def initialize(user)
      return unless user.admin?

      can :read, Order
      can :read, Trade
      can :read, Proof
      can :update, Proof
      can :manage, Document
      can :manage, Member
      can :manage, Ticket
      can :manage, IdDocument
      can :manage, TwoFactor
      can :manage, Coupon
      can :manage, Order
      can :manage, Trade
      can :manage, Revenue

      can :menu, Deposit
      can :menu, Trade
    end
  end
end

config / routes / admin.rb

namespace :admin do
namespace :statistic do
    resource :orders, :only => :show
    resource :trades, :only => :show
  end
end

我检查了一下,不知道在开发服务器而不是远程服务器上工作时会丢失什么。

1 个答案:

答案 0 :(得分:0)

所以我发现问题出在 ability.rb Order中没有定义ability.rb的{​​{1}}。

所以我不得不在 ability.rb

中定义它
:menu

然后在由Cancancan驱动的Navbar中,将Order添加到module Admin class Ability include CanCan::Ability def initialize(user) return unless user.admin? can :read, Order can :read, Trade can :read, Proof can :update, Proof can :manage, Document can :manage, Member can :manage, Ticket can :manage, IdDocument can :manage, TwoFactor can :manage, Coupon can :manage, Order can :manage, Trade can :manage, Revenue can :menu, Deposit can :menu, Trade can :menu, Order # So I added this for `Order` to be references as `:menu` by admin. end end end 语句

if