【问题标题】:Rails Admin not listing recordsRails 管理员未列出记录
【发布时间】:2020-01-08 10:29:46
【问题描述】:

所以我为我的 mongoid 模型创建了一个自定义操作,用于将 XSL 文档上传到 MongoDB。 此操作运行良好,我可以看到 XSL 文档和模型记录已保存在数据库中,它会将我返回到我的列表,我可以在其中查看样式表的名称等。

当我尝试从操作外部访问此列表(即浏览到 /admin/xsl_sheet)时,我得到“Nothing to display”。我不明白为什么会这样。

型号:

require 'mongoid/grid_fs'

class XslSheet
  include Mongoid::Document

  scope :applicationId, -> {where(assetable_id: User.current_user.current_scope['Application']) unless User.current_user.nil? or User.current_user.current_scope.nil?}

  belongs_to :application
  validates_uniqueness_of [:data_file_name, :stylesheet_id], :scope => :assetable_id

  field :data_file_name, type: String
  field :assetable_id, type: Integer
  field :stylesheet_id, type: BSON::ObjectId
end

rails_admin.rb:

# XslSheet
c.model XslSheet do
  label Proc.new {"Xsl Sheet"}
  navigation_label Proc.new {I18n.t('navigation.actions')}
  weight 303
  navigation_icon 'fa fa-envelope-o'
  list do
    binding.pry
    scopes [:applicationId]
    field :data_file_name
    field :assetable_id
    field :stylesheet_id
  end
end

有趣的是,当我通过浏览访问列表时,会触发 rails_admin.rb 中的 binding.pry。 当我创建一个新的XslSheet 并被重定向时,它不会在绑定中捕获。

【问题讨论】:

    标签: ruby-on-rails model action rails-admin


    【解决方案1】:

    我将模型保存到错误的数据库中。

    我切换到另一个数据库保存样式表,忘记切换回默认保存记录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-03
      • 2012-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多