No commit activity in last 3 years
No release in over 3 years
Implements support of RESTful resources with Rails MVC when Javascript is off and bulk operations are required with multiple submit buttons.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.6.0

Runtime

~> 1.3
 Project Readme

Rack RESTful Submit

Implements support of RESTful resources with Rails MVC when Javascript is off and bulk operations are required with multiple submit buttons.

Rack Builder

require 'rack-restful_submit'
use Rack::RestfulSubmit

Rails integration

Install GEM without Bundler

Insert into config/environment.rb:

config.gem "rack-restful_submit"

Run:

rake gems:install

Install GEM with Bundler

Insert into Gemfile:

gem "rack-restful_submit"

Run:

bundle install

Integration

We need to swap our RestfulSubmit middleware with MethodOverride which we don't need anymore.

Insert into config/environment.rb:

config.middleware.swap Rack::MethodOverride, 'Rack::RestfulSubmit'

Usage

In the example below you can see that using submit input with __rewrite name and multi_destroy mapping allows us to convert normal POST request into RESTful one. Don't forget to also insert 2 hidden fields URL and METHOD as shown below. NOTE: I'm aware of that adding collection to RESTfull controller ins't very RESTfull but this is only example of this GEM. If you want fully RESTfull create new controller for the bulk operations.

Example of industries/index.html.erb

<h1>Listing industries</h1>

<form method="post">
<table>
  <tr>
    <th>Name</th>
    <th>Description</th>
  </tr>

<% @industries.each do |industry| %>
  <tr>
    <td><%=h check_box_tag 'industry_ids[]', industry.id %></td>
    <td><%=h link_to industry.name, industry %></td>
    <td><%=h industry.description %></td>
    <td><%= link_to 'Edit', edit_industry_path(industry) %></td>
  </tr>
<% end %>
</table>

<input type="hidden" name="__map[multi_destroy][url]" value="<%= destroy_multiple_industries_url %>" />
<input type="hidden" name="__map[multi_destroy][method]" value="DELETE" />
<input type="submit" name="__rewrite[multi_destroy]" value="Destroy">

</form>

<br />

<%= link_to 'New industry', new_industry_path %>

Routes:

map.resources :industries, :collection => { :destroy_multiple => :delete }

Contribute

The Github way: Fork Me, Hack Me, Push Me, Send Me as Pull Request

License

(c) 2010 Ladislav Martincik - MIT License (see LICENSE)

History

1.2.2 - Relaxed GEM dependecies (Thanks to Vit Vondruch)
1.2.0 - Improvements & Optimalizations for Rails 3 (Thanks to J.Provaznik, F.Vollero)
1.1.2 - Fixing bug with double Rack call()
1.1.1 - Define Gemfile and decrease RSpec version to 1.3.0
1.1.0 - Version with MethodOverride support inside
1.0.0 - First working version