From 7212a7a13c68429b336fe186162593da4ed89b60 Mon Sep 17 00:00:00 2001 From: nathanvda Date: Sat, 7 Apr 2012 01:15:27 +0200 Subject: [PATCH] Update the documentation, to match the availability of some extra options :partial and :render_options. --- README.markdown | 35 ++++++++++++++++++++++++++--------- lib/cocoon/view_helpers.rb | 2 ++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/README.markdown b/README.markdown index 51c1f1d..7e1b796 100644 --- a/README.markdown +++ b/README.markdown @@ -149,14 +149,33 @@ It takes four parameters: - f: referring to the containing form-object - association: the name of the association (plural) of which a new instance needs to be added (symbol or string). - html_options: extra html-options (see `link_to`) - There are three extra options that allow to control the placement of the new link-data: + There are some special options, the first three allow to control the placement of the new link-data: - `data-association-insertion-node` : the jquery selector of the node - `data-association-insertion-method` : jquery method that inserts the new data. `before`, `after`, `append`, `prepend`, etc. Default: `before` - `data-association-insertion-position` : old method specifying where to insert new data. - this setting still works but `data-association-insertion-method` takes precedence. may be removed in a future version. + - `partial`: explicitly declare the name of the partial that will be used + - `render_options` : options passed through to the form-builder function (e.g. `simple_fields_for`, `semantic_fields_for` or `fields_for`). Optionally you could also leave out the name and supply a block that is captured to give the name (if you want to do something more complicated). +#### :render_options +Inside the `html_options` you can add an option `:render_options`, and the containing hash will be handed down to the form-builder for the inserted +form. E.g. especially when using `twitter-bootstrap` and `simple_form` together, the `simple_fields_for` needs the option `:wrapper => 'inline'` which can +be handed down as follows: + +````haml += link_to_add_association 'add something', f, :something, :render_options => {:wrapper => 'inline' } +```` + +#### :partial + +To overrule the default partial name, e.g. because it shared between multiple views, write + +````haml += link_to_add_association 'add something', f, :something, :partial => 'shared/something_fields' +```` + ### link_to_remove_association @@ -171,13 +190,6 @@ It takes three parameters: Optionally you could also leave out the name and supply a block that is captured to give the name (if you want to do something more complicated). -Inside the `html_options` you can add an option `:render_options`, and the containing hash will be handed down to the form-builder for the inserted -form. E.g. especially when using `twitter-bootstrap` and `simple_form` together, the `simple_fields_for` needs the option `:wrapper => 'inline'` which can -be handed down as follows: - -````haml -= link_to_add_association 'add something', f, :something, :render_options => {:wrapper => 'inline' } -```` ### Callbacks (upon insert and remove of items) @@ -234,7 +246,12 @@ The `association-insertion-method` will determine where to add it in relation wi ### Partial -The partial should be named `__fields`, and should start with a container (e.g. `div`) of class `.nested-fields`. +If no explicit partial-name is given, `cocoon` looks for a file named `__fields`. +To override the default partial-name use the option `:partial`. + +For the javascript to behave correctly, the partial should start with a container (e.g. `div`) of class `.nested-fields`. + + There is no limit to the amount of nesting, though. diff --git a/lib/cocoon/view_helpers.rb b/lib/cocoon/view_helpers.rb index 8072a8a..d20f88d 100644 --- a/lib/cocoon/view_helpers.rb +++ b/lib/cocoon/view_helpers.rb @@ -45,6 +45,8 @@ module Cocoon # - *f* : the form this should come in (the formtastic form) # - *association* : the associated objects, e.g. :tasks, this should be the name of the has_many relation. # - *html_options*: html options to be passed to link_to (see link_to) + # - *:render_options* : options passed to `simple_fields_for, semantic_fields_for or fields_for` + # - *:partial* : explicitly override the default partial name # - *&block*: see link_to def link_to_add_association(*args, &block)