Skip to content

Adding custom actions

scambra edited this page May 10, 2012 · 15 revisions

When you add custom actions to a controller which uses ActiveScaffold, probably you will want to keep look and feel. Also, you have to follow some conventions so your action behaves as default actions, and ActiveScaffold provides some methods to DRY your code.

Process and refresh action

One of the easiest actions you can add, is an action which update some records and refresh the list. It could be an action which acts over some marked records, or whatever you can imagine.

Action links will be rendered inline by default, but you must remember to set :position to false, because your action won't return html code. On the other hand, you must call list method after doing your processing. List method will load records for last page you visited, obeying your last search if it's enabled.

  class InvoicesController < ApplicationController
    active_scaffold do |config|
      config.action_links.add :paid, :position => nil
      [more configuration]
    end

    def paid
      [some processing here]
      list
    end
  end
Clone this wiki locally