【问题标题】:Rails_admin remove the optional labelsRails_admin 删除可选标签
【发布时间】:2017-05-31 05:28:32
【问题描述】:

我是 ruby​​ on rails 的新手,我在我的应用程序中使用 rails_admin gem 作为管理面板。但是它有很多“添加新”的标签。但是,有些我不需要。我已经阅读了 https://github.com/sferik/rails_admin/wiki 的 gem 文件。但仍然很困惑如何删除它们?enter image description here

而且我不知道如何将当前用户id添加到这篇文章中,所以我不需要在这里选择用户。

提前感谢。

【问题讨论】:

    标签: ruby ruby-on-rails-5 rails-admin


    【解决方案1】:

    我将尝试使用代码 sn-p 来回答您的两个问题,请阅读 厘米

    class YourObject < ApplicationRecord
      rails_admin do
        edit do
          field :user do
            help nil # This is the word 'Required' in your screenshot
            label 'Person' # for rails admin the label might mean something different than to you in this question
    
            default_value do
              bindings[:view]._current_user.id # This is what you want as the default
            end
    
            read_only true # You can go as far as not letting the current user to change this field
          end
        end
      end
    end
    

    【讨论】:

    • 感谢您的帮助关键字!
    【解决方案2】:

    您还可以使用删除“可选”关键字

    help false
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-21
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      相关资源
      最近更新 更多