Sometimes I had the issue that my list view was configured with some action_links for nesting, crud actions and some additional ones. The resulting list view included a really huge action column on the right. The same sometimes happens for collection actions.
In my opinion a developer should be able to group these actions together to improve usability. If you agree, you will be happy because from now on Activescaffold offers that feature out of the box.
We will use my little howto application as usual.
First of all let s make sure that teams controller has a configured nested link.
class TeamsController < ApplicationController
active_scaffold :team do |conf|
....
conf.nested.add_link(:players)
....
end
end
Next we will create routing entries (conf/routes.rb) for a few dummy actions:
resources :teams do as_routes put :dummy1, : on => :collection put :dummy2, : on => :collection put :dummy3, : on => :collection put :dummy1, : on => :member put :dummy2, : on => :member put :dummy3, : on => :member end
Ok, that s it we ve prepared our application. Let s talk a little bit about the grouping of action_links.
Currently, if you want to add an action_link to your controller you do something like ‘conf.action_links << ….'. Internally, these are stored in an array. If list header is rendered all action_links of type 'collection' are selected and the same happens for type 'member' for each list row.
The grouping is achieved by changing the array to a tree structure. Leafs are representing action_links and nodes represent our groups. Two groups are automatically created: 'member' and 'collection'. I hope it s quite obvious why.
Let s start with the first example:
We would like to add all collection actions (create, search) to a group 'menu' for our teams controller.
class TeamsController < ApplicationController
active_scaffold :team do |conf|
....
conf.search.action_group = 'collection.menu'
conf.create.action_group = 'collection.menu'
....
end
end
If everything is working you should see a menu link at the top of your teams list view, which opens a "submenu" when hovering over it.
2. Example: We would like to group all member actions for all controllers (application_controller.rb).
ActiveScaffold.set_defaults do |conf| conf.show.action_group = 'member.actions.crud' conf.delete.action_group = 'member.actions.crud' conf.update.action_group = 'member.actions.crud' conf.nested.action_group = 'member.actions.nested' end
3. Example: Adding collection actions to Teams Controller
class TeamsController < ApplicationController
active_scaffold :team do |conf|
....
conf.action_links.collection.custom do |group|
group.add 'dummy1', :confirm => 'are_you_sure', :type => :collection, :method => :put, :position => false
group.level_2 do |group|
group.add 'dummy2', :confirm => 'are_you_sure', :type => :collection, :method => :put, :position => false
end
group.add 'dummy3', :confirm => 'are_you_sure', :type => :collection, :method => :put, :position => false
end
....
end
end
4. Example: Adding member actions to Teams Controller
class TeamsController < ApplicationController
active_scaffold :team do |conf|
....
conf.action_links.member.custom do |group|
group.add 'dummy1', :confirm => 'are_you_sure', :type => :member, :method => :put, :position => false
group.level_2 do |group|
group.add 'dummy2', :confirm => 'are_you_sure', :type => :member, :method => :put, :position => false
end
group.add 'dummy3', :confirm => 'are_you_sure', :type => :member, :method => :put, :position => false
end
....
end
end
Wish you a great weekend.