将值分配给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; endBut 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 endIf 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
更多推荐
发布评论