(Quick Reference)

chain

目的
Purpose

Uses flash storage to implicitly retain the model following an HTTP redirect from one action to another.

使用例
Examples

def shawshankRedemption = new Book(title: 'The Shawshank Redemption')
chain(action: "details", model: [book: shawshankRedemption])

詳細
Description

使用方法:

Usage:

chain(controller*, action, id*, model, params*)

引数:

Arguments:
  • uri - The full uri to redirect to (example /book/list, book/show/2)
  • controller (optional) - The controller to redirect to; defaults to the current controller if not specified
  • namespace (optional) - the namespace of the controller to chain to
  • action - The action to redirect to, either a string name or a reference to an action within the current controller
  • id (optional) - The id to use in redirection
  • model - The model to chain to the next action
  • params (optional) - Parameters to pass to the action chained to.

The chain method stores the passed model in flash scope and then performs an HTTP redirect. The model is then restored for the next request. The model that will eventually be passed to the view will be created by starting with the model that was passed to the chain method and then adding to that all of the data that is in the model returned by the next action, which may replace some of the data that was in the model originally passed to the chain method. For example:

def one() {
    chain action: 'two', model: [name: 'Tony', town: 'Birmingham']
}

def two() { [name: 'Anthony', country: 'England'] }

If a request is sent to the one action, that action chains to the two action which returns a model. The model that is passed to the view would contain [name: 'Anthony', town: 'Birmingham', country: 'England']

The chain method requires either a URI to redirect to or a controller/action/id name combination