No commit activity in last 3 years
No release in over 3 years
A Rack middleware to support conditional requests from the browser
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

Rack::Conditional::Forms

Rack::ConditionalForms allows forms to override If-Match and If-Unmodified-Since headers, using _if_match and _if_unmodified_since keys, respectively, allowing conditional POST, PUT and DELETE requests from the browser.

Installation

Add this line to your application's Gemfile:

gem 'rack-conditional-forms'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-conditional-forms

Usage

require 'rack/conditional-forms'
use Rack::ConditionalForms

To use Rack::ConditionalForms in your Rails application, add the following line to your application config file (config/application.rb for Rails 3, config/environment.rb for Rails 2):

config.middleware.use Rack::ConditionalForms

Prepend the hidden fields to your form:

<form action="/123" method="POST">
  <fieldset>
    <input name="_method" type="hidden" value="PUT" />
    <input name="_if_match" type="hidden" value='202cb962ac59075b964b07152d234b70' />
    <input name="_if_unmodified_since" type="hidden" value="Tue, 08 May 2012 00:00:00 GMT" />
    <p>
      <label for="title"></label>
      <input name="title" value="Example form" />
    </p>
    <p>
      <input type="submit" />
    </p>
  </fieldset>
</form>

The request's HTTP_IF_MATCH and HTTP_IF_UNMODIFIED_SINCE headers will then be set to "202cb962ac59075b964b07152d234b70" and Tue, 08 May 2012 00:00:00 GMT, respectively.

Contributing

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