gpt4 book ai didi

ruby-on-rails - 如何删除事件管理员节目中的编辑按钮

转载 作者:行者123 更新时间:2023-12-02 15:09:54 26 4
gpt4 key购买 nike

我想删除事件管理员显示页面上的任何记录的编辑按钮,但月份和年份等于当前月份和年份的记录除外。

我能够在索引中做到这一点

  if (es.month == Date.today.strftime("%m").to_i) && (es.year == Date.today.strftime("%Y").to_i )
span link_to 'Edit', "/executive_summaries/#{es.id}/edit"
end

我的 executive_summaryies.rb 包括

ActiveAdmin.register Executive::Summary do
menu :parent => 'Reports'

config.batch_actions = true

. . .

action_item :only => :show do
link_to_function("#{ActiveAdmin::Iconic.icon(:document_stroke)} Print Executive Summary".html_safe, "javascript:print()")

end

. . .

controller do

. . .

def edit
@run_js_functions = %w(ExecutiveSummaries.init)
end

def show
@run_js_functions = %w(ExecutiveSummaries.accordion)
end

. . .

end

当前代码的方式是,编辑按钮显示在标题栏中(我相信默认情况下),旁边有一个打印按钮。 (来自上面节目中的代码)。

如何在显示/查看页面上显示当前月份和年份的记录的编辑按钮?

最佳答案

首先从所有#show 页面中删除编辑按钮:

config.action_items.delete_if {|item| item.name == :edit && item.display_on?(:show) }

然后有条件地添加:

action_item :my_action, only: :show, if: proc { resource.year = Date.today.year && resource.month == Date.today.month }
link_to ...
end

小时/吨https://hungnhotblog.wordpress.com/2016/09/14/conditionally-show-buttons-on-show-page/

关于ruby-on-rails - 如何删除事件管理员节目中的编辑按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44723359/

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