Rails管理员不显示广告模型中的任何记录

如何解决Rails管理员不显示广告模型中的任何记录

Rails管理员不显示任何记录。甚至还有102条记录持续存在。

enter image description here

即使未在信息中心中列出

enter image description here

但是我可以看到一个广告

enter image description here

我的广告模型

class Ad < ApplicationRecord
  extend FriendlyId

  belongs_to :category
  belongs_to :user
  has_many :ad_images
  alias_attribute :images,:ad_images
  enum status: [:draft,:review,:published,:moderate]

  friendly_id :title,use: :slugged
  acts_as_paranoid
  after_initialize :set_default_status,:if => :new_record?

  scope :latest,-> { order(time_start: :asc) }
  scope :status_draft,-> { where(status: Ad.statuses[:draft]) }
  scope :status_published,-> { where(status: Ad.statuses[:published]) }
  scope :current_displayed,-> { where('time_start < ? AND time_end > ?',Time.Now,Time.Now) }

  scope :show_active,-> { status_published.latest.current_displayed }
  scope :show_draft,-> { status_draft.latest.current_displayed }

  def should_generate_new_friendly_id?
    slug.blank? || title_changed?
  end

  def set_default_status
    self.status ||= :draft
  end

  def related
    category.ads.where.not(id: id).show_active.limit(6)
  end
end

我的rails_admin.rb

RailsAdmin.config do |config|

  ### Popular gems integration

  ## == Devise ==
  config.authenticate_with do
    warden.authenticate! scope: :user
  end

  ## == method to call for current_user ==
  config.current_user_method(&:current_user)

  ## == CancanCan ==
  config.authorize_with :cancancan

  ## == Pundit ==
  # config.authorize_with :pundit

  ## == PaperTrail ==
  # config.audit_with :paper_trail,'User','PaperTrail::Version' # PaperTrail >= 3.0.0

  ### More at https://github.com/sferik/rails_admin/wiki/Base-configuration

  ## == Gravatar integration ==
  ## To disable Gravatar integration in Navigation Bar set to false
  # config.show_gravatar = true

  config.parent_controller = 'ApplicationController'

  config.actions do
    dashboard                     # mandatory
    index                         # mandatory
    new
    export
    bulk_delete
    show
    edit
    delete
    show_in_app

    ## With an audit adapter,you can add:
    # history_index
    # history_show
  end

  # config.model 'Ad' do
    # list do
      # field :title
      # field :created_at
    # end
  # end
end

cancancan能力文件

# frozen_string_literal: true

class Ability
  include CanCan::Ability

  def initialize(user)
    # Define abilities for the passed in user here. For example:
    #
    user ||= User.new # guest user (not logged in)
    if user.admin?
      can :access,:rails_admin
      can :manage,:all
    end
    #
    # The first argument to `can` is the action you are giving the user
    # permission to do.
    # If you pass :manage it will apply to every action. Other common actions
    # here are :read,:create,:update and :destroy.
    #
    # The second argument is the resource the user can perform the action on.
    # If you pass :all it will apply to every resource. Otherwise pass a Ruby
    # class of the resource.
    #
    # The third argument is an optional hash of conditions to further filter the
    # objects.
    # For example,here the user can only update published articles.
    #
    #   can :update,Article,:published => true
    #
    # See the wiki for details:
    # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
  end
end

我没有为rails_admin和ad.rb模型进行任何精美的配置设置。这发生在开发环境和生产中。我认为这是因为rails_admin隐藏了一些我不知道的东西。我不知道该怎么办。

解决方法

我通过将“广告”模型重命名为“商品”来解决了此问题

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?