README.markdown in roar-rails-0.1.5 vs README.markdown in roar-rails-0.1.6
- old
+ new
@@ -2,10 +2,12 @@
_Makes using Roar's representers in your Rails app fun._
Roar is a framework for parsing and rendering REST documents. For a better overview about representers please check the [roar repository](https://github.com/apotonick/roar#roar).
+Roar-rails gives you conventions and convenient access to a lot of Roar's functionality within your Rails app.
+
## Features
* Rendering with responders
* Parsing incoming documents
* URL helpers in representers
@@ -91,11 +93,26 @@
represents :json, :entity => MusicianRepresenter, :collection => MusicianCollectionRepresenter
```
You might pass strings as representer names to `::represents`, they will be constantized at run-time when needed.
+## Rendering with #render
+In place of `#respond_with`, you can also use `#render` to serialize objects using representers.
+
+```ruby
+class SingersController < ApplicationController
+ include Roar::Rails::ControllerAdditions
+ include Roar::Rails::ControllerAdditions::Render
+
+ def show
+ singer = Singer.find_by_id(params[:id])
+ render json: singer
+ end
+end
+```
+
### Old API Support
If you don't want to write a dedicated representer for a collection of items (highly recommended, thou) but rather use a representer for each item, use the `:represent_items_with` option.
```ruby
@@ -247,9 +264,23 @@
## Autoloading
Put your representers in `app/representers` and they will be autoloaded by Rails. Also, frequently used modules as media representers and features don't need to be required manually.
+## Rails 4.1 + HAL
+
+**Note**: this is a temporary work-around, we're trying to fix that in Rails/roar-rails itself [May 2014].
+
+Rails 4.1 expects you to manually register a global HAL renderer, or `respond_with` will throw the exception `ActionController::MissingRenderer (No renderer defined for format: hal)`.
+
+One fix is to add this to `config/initializers/mime_types.rb` right below `Mime::Type.register 'application/hal+json', :hal`:
+
+```ruby
+ActionController::Renderers.add :hal do |obj, options|
+ self.content_type ||= Mime[:hal]
+ obj.to_hal
+end
+```
## Contributors
* [Railslove](http://www.railslove.de) and especially Michael Bumann [bumi] have heavily supported development of roar-rails ("resource :singers").