gpt4 book ai didi

ruby-on-rails - 无法设置 :maxlength in ActiveAdmin panel, Rails 4

转载 作者:行者123 更新时间:2023-12-04 17:58:21 25 4
gpt4 key购买 nike

问题: 我想限制描述字段的输入字符。我对电话号码做了类似的功能,但我不能对描述字段做同样的事情。

我的代码:

此代码有效:

  f.input :phone_number, :input_html => { :class => 'autogrow', :rows => 1, :cols => 2, :maxlength => 8 }

此代码无效:

f.input :description, :input_html => {:class => 'autogrow', :rows => 10, :cols => 10, :maxlength => 200  }
f.input :description_ru, :input_html => {:class => 'autogrow', :rows => 10, :cols => 10, :maxlength => 200 }

也许 maxlength 只适用于字符串类型的字段?因为 maxlength 适用于电话号码(字符串数据类型)而不适用于 description 和 description_ru(两者都是数据库中的文本数据类型)。

提前致谢!

最佳答案

是的,我认为你是对的,它只适用于字符串类型的字段。

这似乎可行:

f.input :myfield, as: :string, input_html: { maxlength: 50 }

我刚刚遇到了 :text 字段的问题,切换到 :string 为我解决了这个问题。

关于ruby-on-rails - 无法设置 :maxlength in ActiveAdmin panel, Rails 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38422724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com