如何更改 ActiveScaffold“操作”的显示顺序?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
警告:我不知道ActiveScaffold。 这个答案是基于我阅读其源代码。
看起来
action_links
变量是一个自定义数据结构,称为ActionLinks
。 它在ActiveScaffold::DataStructures
中定义。在内部,它有一个
@set
变量,它根本不是一个Set
,而是一个Array
。ActionLinks
有一个add
、delete
和each
方法,充当此@set< 的看门人/代码> 变量。
显示链接时,ActiveScaffold 会执行此操作(在
_list_actions.rhtml
中):因此,无需扩展
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, calledActionLinks
. It's defined inActiveScaffold::DataStructures
.Internally, it has a
@set
variable, which is not aSet
at all, but anArray
.ActionLinks
has anadd
,delete
, andeach
methods that serve as gatekeepers of this@set
variable.When displaying the links, ActiveScaffold does this (in
_list_actions.rhtml
):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.