README.markdown in roar-rails-0.1.0 vs README.markdown in roar-rails-0.1.1
- old
+ new
@@ -143,11 +143,21 @@
```ruby
consume! Singer.new, :current_user => current_user
```
+Note: If you pass in options to a representer, you must process them youself. For rendering, use `:getter` in the representer.
+```ruby
+property :username, getter: lambda { |args| args[:current_user].name }
+```
+
+That'll render the `current_user`'s name as the `username` property.
+
+More docs about passing and processing option can be found [here](https://github.com/apotonick/representable/#passing-options).
+
+
## URL Helpers
Any URL helpers from the Rails app are automatically available in representers.
```ruby
@@ -166,10 +176,43 @@
config.representer.default_url_options = {:host => "127.0.0.1:3000"}
```
Attention: If you are using representers from a gem your Rails URL helpers might not work in these modules. This is due to a [loading order problem](https://groups.google.com/forum/?fromgroups#!topic/rubyonrails-core/5tG5unZ8jDQ) in Rails. As a workaround, don't require the representers in the gem but load them as lately as possible, usually it works when you require in the controller. We are working on fixing that problem.
+## Representing Formats Exclusively
+
+By default, roar-rails will extend/decorate any model passed to `respond_with` for any request format. When adding roar-rails to a legacy project, you might want to restrict roar-rails' representing and fall back to the old behavior for certain formats. This can be configured both globally and on a per action basis.
+
+To restrict representing globally to a particular format you can set the `config.representer.represented_formats` in your environment's configuration to an array of formats. For example the following will only represent hal and json requests.
+
+```ruby
+config.representer.represented_formats = [:hal, :json]
+```
+
+The global configuration (or lack thereof) can be overridden by supplying the `:represented_formats` array when calling `respond_with`. The following will only represent `@resource` for the hal format in the `show` action. For any other format, it will expose the resource using Rails' old behavior.
+
+
+```ruby
+class MyController < ApplicationController
+ def show
+ ...
+ respond_with @resource, :represented_formats => [:hal]
+ end
+end
+```
+
+You can entirely suppress roar-rails in `respond_with` by passing in an empty array.
+
+```ruby
+class MyController < ApplicationController
+ def show
+ ...
+ respond_with @resource, :represented_formats => []
+ end
+end
+```
+
## Testing
## 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.
@@ -181,6 +224,6 @@
[responders]: https://github.com/plataformatec/responders
## License
-Roar-rails is released under the [MIT License](http://www.opensource.org/licenses/MIT).
\ No newline at end of file
+Roar-rails is released under the [MIT License](http://www.opensource.org/licenses/MIT).