Skip to content

Instantly share code, notes, and snippets.

@yagitoshiro
Created December 28, 2014 04:20
Show Gist options
  • Save yagitoshiro/85e6bfdd5e469841814f to your computer and use it in GitHub Desktop.
Save yagitoshiro/85e6bfdd5e469841814f to your computer and use it in GitHub Desktop.
ActiveResourceでLoopbackを使う
#app/models/concerns/loopback.rb
module Loopback
extend ActiveSupport::Concern
included do
class << self
def element_path(id, prefix_options = {}, query_options = nil)
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
"#{prefix(prefix_options)}/#{id}#{query_string(query_options)}"
end
def collection_path(prefix_options = {}, query_options = nil)
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
"#{prefix(prefix_options)}#{query_string(query_options)}"
end
end
self.site = Settings.api_endpoint
self.prefix = "/api/#{self.to_s.capitalize.pluralize}/"
end
end
# Model
require 'active_resource'
class Entry < ActiveResource::Base
include Loopback
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment