Module | Camping |
In: |
lib/reststop.rb
|
Extends and overrides Camping for convenient RESTfulness.
Have a look at:
goes | -> | camping_goes |
alias_method call is conditional only to make `rake package` happy |
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.
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):
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).