views:

590

answers:

1

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.

+1  A: 

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.

Jordi Bunster