Skip to content

Instantly share code, notes, and snippets.

@danielevans
Last active August 29, 2015 13:56
Show Gist options
  • Save danielevans/8836617 to your computer and use it in GitHub Desktop.
Save danielevans/8836617 to your computer and use it in GitHub Desktop.
Rails app with rails-api, inherited_resources, acitve_model_serializers and has_scope
# app/controllers/api/base_controller.rb
class Api::BaseController < ActionController::API
include ActionController::MimeResponds
include ActionController::StrongParameters
include ActionController::ImplicitRender
respond_to :json
serialization_scope :view_context
protected
def self.inherit_resources # le-hack
InheritedResources::Base.inherit_resources(self)
initialize_resources_class_accessors!
create_resources_url_helpers!
end
end
source 'https://rubygems.org'
gem 'active_model_serializers'
gem 'has_scope'
gem 'inherited_resources', '~> 1.3'
gem 'kaminari'
gem 'rails', '4.0.2'
gem 'rails-api'
gem 'pg'
gem install rails-api
rails-api new stgrb_demo --database=postgresql --skip-test-unit --skip-bundle
rails g model post body:text title:string rating:integer
# app/controllers/api/posts_controller.rb
class Api::PostsController < ApplicationController
inherit_resources
has_scope :page, default: 1
protected
def permitted_params
params.permit post: [:text, :title, :rating]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment