【问题标题】:Active Scaffold dynamic action linkActive Scaffold 动态动作链接
【发布时间】:2015-11-13 17:29:58
【问题描述】:

也许有人知道一种制作动态隐藏/显示过滤器操作链接的方法,该链接在点击时更改,而无需编写任何 javascript 或创建部分,只需使用控制器和帮助程序。

所以不要有两个按钮:

config.action_links.add :index, :label=>"Hide", :parameters => {:cancelled => false}, :position => false
config.action_links.add :index, :label=>"Show", :parameters => {}, :position => false

如果有一个动态按钮可以在点击时从隐藏 - 显示发生变化,那就太棒了

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.2 activescaffold


    【解决方案1】:

    重要的是,当您更改链接时,即使使用 :dynamic_parameters 属性,除非您指定,否则它们不会重新呈现

    config.list.refresh_with_header = true

    在您的配置中。一旦你这样做了,它只是代码。

    在我的例子中,我有一个带有可选附加文件的记录列表。我想在显示所有记录的列表和仅显示带有附件的记录之间切换。我有一个布尔参数:with_attachments,即'0''1'

    动作链接看起来像

    config.action_links.add :index, label: 'Show All', parameters: { with_attachments: '0' }, position: false
    config.action_links.add :index, label: 'Attachment Only', parameters: { with_attachments: '1' }, position: false
    config.list.refresh_with_header = true # Refresh action buttons!
    

    index 方法将hidden 标签应用于当前选中的选项。

    def index
      current = params[:with_attachments] || '0'
      active_scaffold_config.action_links.each do |link|
        # For :index actions (filtering the list)
        if link.action == :index
          # hide the one that would refresh with the current parameter value
          link.html_options[:hidden] = (link.parameters[:with_attachments] == current)
        end
      end
      super
    end
    

    还有让隐藏动作不可见的 CSS

    .active-scaffold-header .actions a[hidden=hidden] {
      display: none;
    }
    

    您可能只需要一个按钮和 :dynamic_parameters 就可以做到这一点,但由于我通过 CSS 附加了图标(为简单起见省略了),因此该解决方案对我不起作用。

    【讨论】:

      猜你喜欢
      • 2017-02-02
      • 2021-01-27
      • 1970-01-01
      • 1970-01-01
      • 2010-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多