Sha256: 408e223988ec3ccac1b1d13dfb96afbdf3ad60ec982f13bd13f74410519c3f9f

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

# BatchActions

This gem adds generic support for batch actions to Rails controllers.

[![Travis CI](https://secure.travis-ci.org/grindars/batch_actions.png)](https://travis-ci.org/grindars/batch_actions)
[![Code Climate](https://codeclimate.com/github/grindars/batch_actions.png)](https://codeclimate.com/github/grindars/batch_actions)

Sponsored by [Evil Martians](http://evilmartians.com/).

## Installation

Add this line to your application's Gemfile:

    gem 'batch_actions'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install batch_actions

## Usage

```ruby
class PostController < ApplicationController
  include BatchActions

  batch_model Post

  # Runs `model.publish` for every model from params[:ids]
  batch_action :publish

  # Runs `model.destroy` for every model from params[:ids] or throws exception unless you can
  batch_action :destroy, if: ->() { can? :destroy, Post }

  # Runs block for every model from params[:ids]
  batch_action :specific do |objects|
    objects.each{|x| x.specific!}
  end

  # Runs `model.resurrect` for every model from returned relation
  batch_action :resurrect, :scope => ->(ids) { Post.where(other_ids: ids) }
end
```

Note that you can omit `batch_model` call if you use the [inherited_resources](https://github.com/josevalim/inherited_resources) gem. It grabs your model class from `resource_class`.

There's one more important thing to know: set of active batch actions can be retrieved from controller by calling `batch_actions` on controller instance.

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
batch_actions-0.0.2 README.md
batch_actions-0.0.1 README.md