将值分配给rails

编程入门 行业动态 更新时间:2024-10-28 06:36:50
将值分配给rails_admin列表字段(Assign value to rails_admin list field)

我使用的是rails_admin gem而不是数据库中的实际id字段,我只想使用当前的数字,这样管理员就无法查看我的数据库中的实际ID。 到目前为止我尝试过:

# Fields in Projects model config.model 'Project' do @currentId = 1; list do field :id do @currentId end field :year field :title field :intro field :description field :confidential field :star field :image end @currentId += 1; end

但这只显示我的数据库ID。 有什么建议么?

I am using rails_admin gem and instead of the actual id field from the database I want to use just a current number, so that the admin won't get to see what the actual id is in my db. So far I tried:

# Fields in Projects model config.model 'Project' do @currentId = 1; list do field :id do @currentId end field :year field :title field :intro field :description field :confidential field :star field :image end @currentId += 1; end

But this displays just my db id. Any suggestions?

最满意答案

您可以为此目的执行以下操作。

隐藏字段

list do configure :id do hide end include_all_fields # all other default fields will be added after, conveniently end

排除字段

list do exclude_fields :id end

格式字段值

list do field :id do formatted_value do # used in form views value++ end end include_all_fields # all other default fields will be added after, conveniently end

有关更多配置,请访问https://github.com/sferik/rails_admin/wiki/Fields

[Answer]: As long as the db does reset it's id value (e.g: MySql), you can do this:

currentId = 0 # Fields in Projects list config.model 'Project' do list do field :id do formatted_value do currentId +=1 end end field :year field :title field :intro field :description field :confidential field :star field :image end

If the database keeps incrementing that value, than the current user has to be passed as a binding and the id can be easily tweaked in the main list view of rails_admin

更多推荐

本文发布于:2023-04-27 12:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327066.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:将值分   rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!