Day 6: Custom action_links in ActiveScaffold

The Basecamp visualization application will provide time views for each Person and Project. The user selects the Person or Project from a table (rendered by ActiveScaffold) and indicates that statistics are to be shown by clicking a link in the cell.

To link this view change to the ActiveScaffold row, we will use the action_link property of our configuration. The API is regrettably sparse, but a little bit of digging brought up this ActiveScaffold wiki entry and an example at the end of the newbie guide.

To keep things simple, I am currently presenting the data as a seperate barebones view. My Person controller code is:

app/controllers/people_controller.rb

class PeopleController < ApplicationControllerlayout "activescaffold"
  active_scaffold(:person) do |config|
    config.label = "People"
    config.columns = [:first_name, :last_name, :title, :im_handle]
    config.columns[:im_handle].label = "IM Handle"
    config.actions.exclude :create, :delete, :edit, :show, :search
    config.action_links.add 'time_per_person', :label => "Time", :type => :record, :page => true
    list.columns.exclude :timeentries
    list.sorting = {:last_name => 'ASC'}
  end

  def time_per_person
    @buns = "foo"
  end

end

config.action_links.add breaks down like this:
Parameter 0: String of the controller method to invoke (Ex: ‘time_per_person’)
:label : Displayed label for the link (Ex: “Time”)
:type : Is this link shown once per :record (row) or once per :table?
:page : Load the result as a new view?
time_per_person currently sets a test variable that is shown in the view:

app/views/people/time_per_person.rhtml

<%= @buns %>

This variable will hold my generated image’s filename and will be presented as an embedded image.

~ by philippp on June 20, 2007.

Leave a Reply