我想要做一个当前的数字,而不是在我的仪表板上的列表视图中的正确的数据库id字段。为此,我使用了来自rails_admin的rails_admin。唯一的问题是,在表单呈现之后,我希望重置该值,因为在我重新加载页面之后,id一直在递增,并且永远不会返回到0。如何在rails管理中的字段中重置formatted_value。到目前为止,我尝试了这个没有多少运气:
config/initializers/rails_admin.rb
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
currentId = 0发布于 2016-11-16 15:36:27
解出
我将field :id留在初始化程序中,并过度删除app/views/rails_admin/main/index.html.haml with。
%th.last.shrink
%tbody
- currentId = 1
- @objects.each do |object|
%tr{class: "#{@abstract_model.param_key}_row"}
%td
= check_box_tag "bulk_ids[]", object.id, false
- if @other_left_link ||= other_left && index_path(params.except('set').merge(params[:set].to_i != 1 ? {set: (params[:set].to_i - 1)} : {}))
%td.other.left= link_to "...", @other_left_link, class: 'pjax'
- properties.map{ |property| property.bind(:object, object) }.each do |property|
- if property.name.to_s == "id"
- value = currentId
- currentId += 1
- else
- value = property.pretty_valuehttps://stackoverflow.com/questions/40628284
复制相似问题