为什么在我部署的代码上单击特定 link 时会出现 500 错误?
Why do I get 500 Error upon clicking a particular link on my deployed code?
当我在远程服务器上的 运行 应用程序上访问特定端点时,我收到 500 内部错误。然而,代码在我的本地 system/server.
上运行良好
代码:
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
views/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%"
admin/statistic/shared/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
我已经检查过但不知道在开发服务器上而不是在远程服务器上工作遗漏了什么。
所以我发现问题来自ability.rb。 Order
未在 ability.rb
中定义,我引用为 :menu
。
所以我不得不在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
can :menu, Order # So I added this for `Order` to be references as `:menu` by admin.
end
end
end
然后在由 Cancancan 驱动的 Navbar 中,我将 Order 添加到 if
语句
- if can? :menu, Trade || Order # So I added this as well.
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
当我在远程服务器上的 运行 应用程序上访问特定端点时,我收到 500 内部错误。然而,代码在我的本地 system/server.
上运行良好代码:
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
views/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%"
admin/statistic/shared/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
我已经检查过但不知道在开发服务器上而不是在远程服务器上工作遗漏了什么。
所以我发现问题来自ability.rb。 Order
未在 ability.rb
中定义,我引用为 :menu
。
所以我不得不在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
can :menu, Order # So I added this for `Order` to be references as `:menu` by admin.
end
end
end
然后在由 Cancancan 驱动的 Navbar 中,我将 Order 添加到 if
语句
- if can? :menu, Trade || Order # So I added this as well.
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