Thin-man

A Rails restful-ajax library that makes web apps lively while keeping all the logic on the server.

View the Project on GitHub edraut/thin-man

View Options

Helper Options

insert_method: <jQuery insert method>
Insert the response html using this jQuery insert method, e.g. `html`, `append`, `prepend`, `before`, `after`, etc. Any valid jQuery method for placing content in relation to the target may be used. It will be called thusly `$(target)[insert_method](response_html)`. The default is `html`

Data attribute options for both links and forms

You can apply these data attributes to dom elements in your views and ThinMan will bind them with the behavior described.

data-ajax-link: true
Apply ajax behavior to this link

data-ajax-target: <css selector>
The DOM element represented by the css selector will be the target for placing the ajax response HTML. The default behavior is to replace the innerHTML of the element with the response HTML. See data-insert-method for options to configure the placement in relation to the target. For ajax delete links, this is the DOM element to remove after a success response from the server.

data-insert-method: <jQuery insertion method>
How to place the response HTML in relation to the selected target. Uses jQuery insertion methods, e.g. 'html', 'append', 'prepend', 'after', 'before', etc. See the jQuery manipulation docs for more options. The default is 'html'.

data-error-target: <css selector>
Where to place the response HTML if the request generated a conflict on the server (e.g. the request failed validation). This only takes precedence if the server responds with a 409 CONFLICT. It does not handle 500-class errors. The default behavior is to use the same DOM element as data-ajax-target.

data-empty-on-success: <css selector>
Thin_man will empty the contents of the element selected by the provided selector if the request is successful.

data-remove-on-success: <css selector>
Thin_man will remove the element selected by the provided selector if the request is successful.

Link-only data-attribute options

data-method: <HTTP method>
The HTTP method to use in sending the ajax request

Delete-link-only data-attribute options

data-ajax-target: <css selector>
The DOM element that should be removed after a success response for the ajax request