Module Camping
In: lib/reststop.rb

Extends and overrides Camping for convenient RESTfulness.

Have a look at:

Methods

qsp   qxp   render   service  

Classes and Modules

Module Camping::Controllers
Module Camping::Helpers
Module Camping::Views

External Aliases

goes -> camping_goes
  alias_method call is conditional only to make `rake package` happy

Public Class methods

Overrides Camping‘s query parsing method so that XML input is parsed into @input as an object usable more or less in the same manner as a standard Hash input.

This is necessary for dealing with ActiveResource calls, since ActiveResource submits its POST and PUT data as XML instead of the standard CGI query string.

The method automatically determines whether input is XML or standard CGI query and parses it accordingly.

Parse an XML query (input) into a Hash usable more or less the same way as a Camping‘s standard Hash input.

Public Instance methods

Overrides Camping‘s render method to add the ability to specify a format module when rendering a view.

The format can also be specified in other ways (shown in this order of precedence):

  1. By providing a second parameter to render() (eg: render(:foo, :HTML))
  2. By setting the @format variable
  3. By providing a ‘format’ parameter in the request (i.e. @input[:format])
  4. By adding a file-format extension to the url (e.g. /items.xml or /items/2.html).

For example, you could have:

  module Foobar::Views

    module HTML
      def foo
        # ... render some HTML content
      end
    end

    module RSS
      def foo
        # ... render some RSS content
      end
    end

  end

Then in your controller, you would call render() like this:

  render(:foo, :HTML) # render the HTML version of foo

or

  render(:foo, :RSS) # render the RSS version of foo

or

  @format = :RSS
  render(:foo) # render the RSS version of foo

or

  # url is /foobar/1?format=RSS
  render(:foo) # render the RSS version of foo

or

  # url is /foobar/1.rss
  render(:foo) # render the RSS version of foo

If no format is specified, render() will behave like it normally does in Camping, by looking for a matching view method directly in the Views module.

You can also specify a default format module by calling default_format after the format module definition. For example:

  module Foobar::Views
    module HTML
      # ... etc.
    end
    default_format :HTML
  end

This override is taken and slightly modified from the Camping mailing list; it fakes PUT/DELETE HTTP methods, since many browsers don‘t support them.

In your forms you will have to add:

input :name => ‘_method’, :type => ‘hidden’, :value => ‘VERB‘

… where VERB is one of put, post, or delete. The form‘s actual :method parameter must be ‘post’ (i.e. :method => post).

[Validate]