Configuration
JR has a few configuration options, though the default settings will work well for most projects. To set configuration options create an initializer and add the options you wish to set. All options have defaults, so you only need to set the options that are different.
Example
You wish to change the way multi word JSON keys are serialized. By default JR uses the JSON API recommendation for dasherizing (foo-bar
) compound words.
Initializer
Create a new file named jsonapi-resources.rb
in your project’s config/initializers
directory and add the following:
JSONAPI.configure do |config| |
Override the defaults
Now override the json_key_format
and route_format
to camelize (fooBar
) compound words:
JSONAPI.configure do |config| |
See formatters for more details on formatters.
Defaults
The default configuration options are shown below:
JSONAPI.configure do |config| |
Note: If using custom classes (such as a CustomPaginator
), be sure to require them at the top of the initializer before usage.