I followed the settings described in active_model_serializers guide to couple a Rails 5 API with Ember 3 app.
In Rails ShopLanguagesController
, I modified shop_language_params
method as described in the above guide:
private
def shop_language_params
#params.require(:shop_language).permit(:shop_id, :language_id, :modified_by)
ActiveModelSerializers::Deserialization.jsonapi_parse!(params, only: [:shop_id, :language_id, :modified_by] )
end
Here is what I get when I post the following data from Ember app (seen in Rails log console):
Started POST "/shops/613/languages" for 127.0.0.1 at 2018-04-09 16:53:05 +0200
Processing by ShopLanguagesController#create as JSONAPI
Parameters: {"data"=>{"attributes"=>{"modified_by"=>"Z28SCAMB"}, "relationships"=>{"shop"=>{"data"=>{"type"=>"shops", "id"=>"613"}}, "language"=>{"data"=>{"type"=>"languages", "id"=>"374"}}}, "type"=>"shop-languages"}, "shop_id"=>"613"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."username" = $1 LIMIT $2 [["username", "Z28SCAMB"], ["LIMIT", 1]]
Shop Load (0.4ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 613], ["LIMIT", 1]]
++++ params: {:modified_by=>"Z28SCAMB"}
The posted data seems to be correct.
How to extract the needed parameters (for example, language_id
) from this JSON ?