【问题标题】:Condition checking in active admin table_for活动管理员 table_for 中的条件检查
【发布时间】:2016-02-04 07:19:43
【问题描述】:

我有 2 个表预购和付款与 has_many 关系,我只想在检查状态(布尔)条件后显示表中的内容,我尝试使用以下代码 sn-p 但它不起作用?如何检查table_for里面的条件?

  panel "payment" do
    table_for preorder.payments do |a|
      if a.status.nil?
        column "Received On",     :created_at
        column "Details & Notes", :payment_details
        column "Amount",          :amount_in_dollars
      end
    end
  end

支付模式 attr_accessible :created_at, :payment_details, :status, :amount_in_dollars 属于_to :preorder

预购款 attr_accessible :name, :order has_many : 付款

我想根据状态在预购管理页面中显示付款详情。

【问题讨论】:

  • 使用if a.status 而不是if a.status.nil?
  • 它的抛出错误为未定义的方法'状态'

标签: ruby-on-rails activeadmin


【解决方案1】:

试试下面的代码。我希望它有效。

panel "payment" do
 table_for preorder.payments do |a|
   unless a.blank?
    if a.status
      column "Received On",     :created_at
      column "Details & Notes", :payment_details
      column "Amount",          :amount_in_dollars
    end
   end
 end
end

【讨论】:

  • 仅出于测试目的,请您在 Rails 控制台中运行 Preorder.first.payments.last.status 看看是否有任何结果。
  • 我的猜测是您尚未将列状态添加到您的付款表中。请检查您的 schema.rb 文件中的付款表一次。
  • 控制台将错误显示为未定义的方法“付款”
  • 应该是 Preorder.first.payments.last.status 而不是 Preorder.first.Payments.last.status
猜你喜欢
  • 1970-01-01
  • 2011-11-27
  • 2012-03-23
  • 2018-04-18
  • 1970-01-01
  • 1970-01-01
  • 2019-02-10
  • 2012-07-27
  • 1970-01-01
相关资源
最近更新 更多