Notes on configuring Ruby on Rails to use ActiveModelSerializers with Ember.js
Ruby Notes:
Configure ActiveModelSerializers to use 'embed = :ids, embed_in_root = true'
Ember will expect the response to be in a format like this:
{
"famous_person": { "id": 1, "first_name": "Barack", "last_name": "Obama", "occupation": "President" } }
Controller needs to reflect that the JSON parameters will be included in a hash of the object's name
Example:
desc 'Create a widget.' params do requires :widget, type: Hash do requires :name, type: String, desc: 'Widget name' end end post do widget_params = params["widget"] Widget.create!({ name: widget_params[:name], }) end
Logging:
To enable logging of API requests add the gem 'grape-middleware-logger' to your Gemfile
gem 'grape', '>= 0.14.0'
gem 'grape-middleware-logger'
Ember Notes:
- ember install active-model-adapter
- Follow the instructions at -> https://github.com/ember-data/active-model-adapter#usage