Skip to content

Instantly share code, notes, and snippets.

@Startouf
Startouf / sideposting_educations_with_schools_jsonapi_request_payload.json
Last active November 30, 2017 22:48
Sideposting with json:api, with `method` allowing to desambiguate operations
{
"data": {
"type": "profile",
"relationships": {
"educations": {
"data": [
{
"type": "profile/education",
"temp-id": 0,
"method": "create"
@Startouf
Startouf / gist:937492b1ad86aa035b9660a519802f18
Last active September 8, 2017 00:16
Conditional rendering of relationship for tricky situation
```ruby
class User
embeds_many :attacker_performance
embeds_many :defender_performance
has_many :matches_as_attacker
has_many :matches_as_defender
end
class AttackerPerformance
embedded_in :user
@Startouf
Startouf / Share rspec example for a sideposting concern
Created July 23, 2017 13:55
Refactor jsonapi-suite sideposting into shared examples for RSpec
# spec/requests/api/create_post_spec.rb
require 'rails_helper'
require 'requests/api/concerns/commentable_sidepost_spec.rb'
describe API::V1::PostsController, type: :request do
let(:user) { create(:user) }
let(:author) { user }
let(:post_attributes) do {
title: Faker::Lorem::Sentence.new,
author_id: author.id.to_s
@Startouf
Startouf / algolia_search_for_jsonapi_and_mongoid.rb
Created June 22, 2017 15:04
Search adapters for Jsonapi-suite
# Background : jsonapi-powered search controller
class MySearchController < JsonapiPoweredController
jsonapi resource: ::Public::Search::ProfessionalResource
def index
render_jsonapi(search_scope)
end
def search_scope
Searcher::SearchScopeProxy.new(
collection: Professional,
@Startouf
Startouf / google_analytics_turbolinks5.js
Created August 20, 2016 22:09
Google Analytics for Turbolinks 5 (& Rails 5)
// Google Analytics code to work with Turbolniks 5
this.GoogleAnalytics = (function() {
function GoogleAnalytics() {}
GoogleAnalytics.load = function() {
var firstScript, ga;
window._gaq = [];
window._gaq.push(["_setAccount", GoogleAnalytics.analyticsId()]);
window._gaq.push(['_setAllowAnchor', true]);