Created
December 28, 2014 04:20
-
-
Save yagitoshiro/85e6bfdd5e469841814f to your computer and use it in GitHub Desktop.
ActiveResourceでLoopbackを使う
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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