Skip to content
jonatas edited this page Sep 14, 2010 · 38 revisions

Action Links are used to tie pieces of ActiveScaffold together, and can be used to integrate your own functionality. They can be attached and configured in a variety of places. Native actions like Create, Update, and Delete have configurable links within their own config sections (e.g. config.create.link), and column objects may themselves have an action link (e.g. config.columns[:username].link). The main config.action_links collection is meant for your custom links.

action

The :action value of the URL

controller v1.1

Lets you specify a different controller for the action link. In version 1.0 you had to sneak this in through the :parameters option.

parameters

Miscellaneous parameters for the URL. In version 1.0, if you want to link to another controller you need to specify a :controller parameter here.

method

Specifies a method for RESTful links. Default is :get.

Values: :get, :post, :put, :delete

type

Determines whether the link appears on each record, or just once for the entire scaffold.

Values: :table, :record

label

The visible text for the link.

confirm

The confirmation message for the link, if any.

security_method

Specifies a method on the controller that determines whether to show this link or not. Note that this does NOT prevent someone from URL hacking.

Values: a symbol naming the method (e.g. :logged_in?)

crud_type

Specifies that the (eventual) CRUD action initiated by this link will be one of the core CRUD types. This is used to check authorization and disable the link.

Values: :create, :read, :update, :destroy

inline

When true, the link will open with an AJAX call, using the :position option.

Values: true, false

page

When true, the link will open with standard HTML behavior.

Values: true, false

popup

When true, the link will open in a new window. Currently there is no configuration option to set the size of the new window.

Values: true, false

position

For inline links, determines where the result goes. When set to false, then ActiveScaffold will not try to automatically place the result (good for RJS responses).

Values:

  • for :type => :table: :top, false.
  • for :type => :record: :replace, :after, :before, and false.

association.reverse

For association columns, lets you specify the reverse association name in case ActiveScaffold is unable to guess itself. For more information see the API: Nested.

html_options

Html attributes to render this action link

Examples:


config.show.link = false     #This removes the show link from the list view,
                              but still allows the show function to be used.
config.update.link.inline = false     #This sets the update link to open in its own page.

To enable or disable action links on a per record basis:

Create an authorized_for? method in your model and return false for disabling action_links based on your conditions. authorized_for? is also used for column level security checks for every CRUD action. For action_links do something like this:



class MyModel < ActiveRecord::Base
  def authorized_for?(*args)
     not [:destroy, :update].include?(args[0][:action]) 
  end
end
Clone this wiki locally