Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save whittle/76df2f1799713977ea4d to your computer and use it in GitHub Desktop.
Save whittle/76df2f1799713977ea4d to your computer and use it in GitHub Desktop.
Example roar-rails app
class SiteFaqsController < ApplicationController
include Roar::Rails::ControllerAdditions
respond_to :hal
def show
respond_with SiteFaq.new('How do I understand recursion?', 'First, you must understand recursion.')
end
end
class SiteFaq < Struct.new(:question, :answer)
end
module SiteFaqRepresenter
include Roar::Representer::JSON::HAL
property :question
property :answer
end
Mime::Type.register 'application/hal+json', :hal
Rails.application.routes.draw do
resources :site_faqs, only: [:show]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment