Last active
August 29, 2015 13:56
-
-
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
This file contains hidden or 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/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 |
This file contains hidden or 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
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' |
This file contains hidden or 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
gem install rails-api | |
rails-api new stgrb_demo --database=postgresql --skip-test-unit --skip-bundle |
This file contains hidden or 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
rails g model post body:text title:string rating:integer |
This file contains hidden or 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/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