如何更改 ActiveScaffold“操作”的显示顺序?

发布于 2024-07-05 05:45:24 字数 532 浏览 12 评论 0原文

我在 Ruby on Rails 应用程序中使用 ActiveScaffold,并使用 CSS 将表中的默认“操作”文本(即“编辑”、“删除”、“显示”)替换为图标。 我还使用 action_link.add 添加了一些自定义操作(“移动”和“复制”)。

为了清楚起见,我希望图标以不同的顺序显示。 具体来说,我希望“编辑”成为第一个显示的图标。

我似乎可以通过更改控制器中的定义顺序来更改 action_links 的顺序。 我还可以通过首先 config.actions.排除所有内容,然后使用 config.actions.add 按特定顺序添加它们来更改默认操作的顺序。

但是,我的自定义操作似乎总是出现在列表中默认操作之前。

理想情况下,我希望它们显示“编辑”“复制”“移动”“删除”(即 - 内置、自定义、自定义、内置)。 谁能建议我如何做到这一点?

我的一个想法是将“编辑”重新定义为自定义操作(使用默认功能),但我也不知道如何去做。

I am using ActiveScaffold in a Ruby on Rails app, and have replaced the default "actions" text in the table (ie. "edit", "delete", "show") with icons using CSS. I have also added a couple of custom actions with action_link.add ("move" and "copy").

For clarity, I would like to have the icons displayed in a different order than they are. Specifically, I would like "edit" to be the first icon displayed.

I seem to be able to change the order of the action_links by the changing the order of definition in the controller. I have also been able to change the order of the default actions by first config.actions.excluding everything, and then adding them with config.actions.add in a specific order.

However, my custom actions always seem to appear before the default actions in the list.

Ideally I would like them to display "edit" "copy" "move" "delete" (ie - built-in, custom, custom, built-in). Can anyone suggest how I might do this?

One idea I had was to re-define "edit" as a custom action (with the default functionality), but I don't know how to go about this either.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢华的一滴泪 2024-07-12 05:45:24

警告:我不知道ActiveScaffold。 这个答案是基于我阅读其源代码。

看起来 action_links 变量是一个自定义数据结构,称为 ActionLinks。 它在 ActiveScaffold::DataStructures 中定义。

在内部,它有一个@set变量,它根本不是一个Set,而是一个ArrayActionLinks 有一个 adddeleteeach 方法,充当此 @set< 的看门人/代码> 变量。

显示链接时,ActiveScaffold 会执行此操作(在 _list_actions.rhtml 中):

<% active_scaffold_config.action_links.each :record do |link| -%>
  # Displays the link (code removed for brevity)
<% end -%>

因此,无需扩展 ActiveScaffold::DataStructures::ActionLinks 即可添加一种对 @set 中的值进行不同排序的方法,似乎没有办法做到这一点,至少一般情况下是这样。

如果我是您,我会添加一个名为 order_by! 的内容,您可以在其中以正确的顺序向它传递一个符号数组,然后它会使用 @set。 这样,您可以在添加完自定义操作后调用它。

Caveat: I don't know ActiveScaffold. This answer is based on me reading its source code.

It looks like the action_links variable is a custom data structure, called ActionLinks. It's defined in ActiveScaffold::DataStructures.

Internally, it has a @set variable, which is not a Set at all, but an Array. ActionLinks has an add, delete, and each methods that serve as gatekeepers of this @set variable.

When displaying the links, ActiveScaffold does this (in _list_actions.rhtml):

<% active_scaffold_config.action_links.each :record do |link| -%>
  # Displays the link (code removed for brevity)
<% end -%>

So, short of extending ActiveScaffold::DataStructures::ActionLinks to add a method to sort the values in @set differently, there doesn't seem to be a way to do it, at least not generally.

If I were you, I'd add something called order_by!, where you pass it an array of symbols, with the proper order, and it resorts @set. That way, you can call it after you're done adding your custom actions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文