├── app ├── mailers │ └── .keep ├── models │ ├── .keep │ ├── concerns │ │ └── .keep │ └── book.rb ├── controllers │ ├── concerns │ │ └── .keep │ ├── application_controller.rb │ └── books_controller.rb ├── jobs │ └── application_job.rb └── serializers │ └── book_serializer.rb ├── lib └── tasks │ └── .keep ├── public ├── favicon.ico ├── robots.txt ├── api-docs.json ├── 500.html ├── 422.html ├── 404.html └── books.json ├── test ├── mailers │ └── .keep ├── models │ ├── .keep │ └── book_test.rb ├── controllers │ ├── .keep │ └── books_controller_test.rb ├── fixtures │ ├── .keep │ ├── files │ │ └── .keep │ └── books.yml ├── integration │ └── .keep └── test_helper.rb ├── bin ├── rake ├── bundle ├── rails ├── update └── setup ├── config ├── initializers │ ├── active_model_serializer.rb │ ├── mime_types.rb │ ├── application_controller_renderer.rb │ ├── callback_terminator.rb │ ├── request_forgery_protection.rb │ ├── filter_parameter_logging.rb │ ├── active_record_belongs_to_required_by_default.rb │ ├── backtrace_silencers.rb │ ├── wrap_parameters.rb │ ├── cors.rb │ ├── inflections.rb │ └── swagger.rb ├── boot.rb ├── environment.rb ├── routes.rb ├── database.yml ├── locales │ └── en.yml ├── secrets.yml ├── environments │ ├── development.rb │ ├── test.rb │ └── production.rb └── application.rb ├── spec ├── models │ └── book_spec.rb ├── requests │ └── books_spec.rb ├── routing │ └── books_routing_spec.rb ├── rails_helper.rb ├── spec_helper.rb └── controllers │ └── books_controller_spec.rb ├── config.ru ├── Rakefile ├── db ├── migrate │ └── 20151127182546_create_books.rb ├── seeds.rb └── schema.rb ├── .gitignore ├── README.md ├── Gemfile └── Gemfile.lock /app/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/models/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/models/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/controllers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/integration/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/files/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | end 3 | -------------------------------------------------------------------------------- /app/models/book.rb: -------------------------------------------------------------------------------- 1 | class Book < ActiveRecord::Base 2 | validates_presence_of :title 3 | end 4 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /config/initializers/active_model_serializer.rb: -------------------------------------------------------------------------------- 1 | ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::JsonApi -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::API 2 | Swagger::Docs::Generator::set_real_methods 3 | end 4 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 2 | 3 | require 'bundler/setup' # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /app/serializers/book_serializer.rb: -------------------------------------------------------------------------------- 1 | class BookSerializer < ActiveModel::Serializer 2 | attributes :id, :title, :page_count, :description, :created_at 3 | end 4 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../../config/application', __FILE__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /spec/models/book_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe Book, :type => :model do 4 | pending "add some examples to (or delete) #{__FILE__}" 5 | end 6 | -------------------------------------------------------------------------------- /test/models/book_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class BookTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | resources :books 3 | # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 4 | end 5 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | ## Change renderer defaults here. 2 | # 3 | # ApplicationController.renderer.defaults.merge!( 4 | # http_host: 'example.org', 5 | # https: false 6 | # ) 7 | -------------------------------------------------------------------------------- /config/initializers/callback_terminator.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Do not halt callback chains when a callback returns false. 4 | ActiveSupport.halt_callback_chains_on_return_false = false 5 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /config/initializers/request_forgery_protection.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Enable origin-checking CSRF mitigation. 4 | Rails.application.config.action_controller.forgery_protection_origin_check = true 5 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /config/initializers/active_record_belongs_to_required_by_default.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Require `belongs_to` associations by default. 4 | Rails.application.config.active_record.belongs_to_required_by_default = true 5 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /test/fixtures/books.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | title: MyString 5 | page_count: 1 6 | description: MyText 7 | 8 | two: 9 | title: MyString 10 | page_count: 1 11 | description: MyText 12 | -------------------------------------------------------------------------------- /db/migrate/20151127182546_create_books.rb: -------------------------------------------------------------------------------- 1 | class CreateBooks < ActiveRecord::Migration 2 | def change 3 | create_table :books do |t| 4 | t.string :title 5 | t.integer :page_count 6 | t.text :description 7 | 8 | t.timestamps 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/requests/books_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe "Books", :type => :request do 4 | describe "GET /books" do 5 | it "works! (now write some real specs)" do 6 | get books_path 7 | expect(response).to have_http_status(200) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) 7 | # Mayor.create(name: 'Emanuel', city: cities.first) 8 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV['RAILS_ENV'] ||= 'test' 2 | require File.expand_path('../../config/environment', __FILE__) 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 7 | fixtures :all 8 | 9 | # Add more helper methods to be used by all tests here... 10 | end 11 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore the default SQLite database. 11 | /db/*.sqlite3 12 | /db/*.sqlite3-journal 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log 16 | /tmp 17 | !/log/.keep 18 | !/tmp/.keep 19 | 20 | /.idea 21 | .rspec -------------------------------------------------------------------------------- /config/initializers/cors.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Avoid CORS issues when API is called from the frontend app. 4 | # Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. 5 | 6 | # Read more: https://github.com/cyu/rack-cors 7 | 8 | # Rails.application.config.middleware.insert_before 0, Rack::Cors do 9 | # allow do 10 | # origins 'example.com' 11 | # 12 | # resource '*', 13 | # headers: :any, 14 | # methods: [:get, :post, :put, :patch, :delete, :options, :head] 15 | # end 16 | # end 17 | -------------------------------------------------------------------------------- /public/api-docs.json: -------------------------------------------------------------------------------- 1 | { 2 | "apiVersion": "1.0", 3 | "swaggerVersion": "1.2", 4 | "basePath": "http://api.booksapp.com/", 5 | "apis": [ 6 | { 7 | "path": "books.{format}", 8 | "description": "Books" 9 | } 10 | ], 11 | "info": { 12 | "title": "Bookstore App", 13 | "description": "This is an API for an online bookstore", 14 | "termsOfServiceUrl": "https://github.com/switzersc/rails-5-api-tutorial", 15 | "contact": "shelbyswitzer@gmail.com", 16 | "license": "Apache 2.0", 17 | "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.html" 18 | } 19 | } -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: db/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: db/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: db/production.sqlite3 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rails 5 API tutorial 2 | 3 | This demo shows a Rails 5 API with Swagger documentation and Test::Unit and Rspec testing. It uses ActiveModel::Serializers to comply with the JSON+API hypermedia spec. 4 | 5 | 6 | ## Getting started with Rails 5 and creating your own books API 7 | 8 | Install Rails 5: 9 | 10 | git clone https://github.com/rails/rails.git 11 | cd rails/ 12 | bundle install 13 | 14 | Generate API: 15 | 16 | bundle exec railties/exe/rails new ../books --edge --dev --api 17 | 18 | Create Scaffold: 19 | 20 | bundle exec rails generate scaffold books title description:text page_count:integer 21 | 22 | Migrate the database: 23 | 24 | bundle exec rake db:migrate 25 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /spec/routing/books_routing_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | RSpec.describe BooksController, :type => :routing do 4 | describe "routing" do 5 | 6 | it "routes to #index" do 7 | expect(:get => "/books").to route_to("books#index") 8 | end 9 | 10 | it "routes to #show" do 11 | expect(:get => "/books/1").to route_to("books#show", :id => "1") 12 | end 13 | 14 | it "routes to #create" do 15 | expect(:post => "/books").to route_to("books#create") 16 | end 17 | 18 | it "routes to #update" do 19 | expect(:put => "/books/1").to route_to("books#update", :id => "1") 20 | end 21 | 22 | it "routes to #destroy" do 23 | expect(:delete => "/books/1").to route_to("books#destroy", :id => "1") 24 | end 25 | 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /bin/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | require 'fileutils' 4 | include FileUtils 5 | 6 | # path to your application root. 7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | chdir APP_ROOT do 14 | # This script is a way to update your development environment automatically. 15 | # Add necessary update steps to this file. 16 | 17 | puts '== Installing dependencies ==' 18 | system! 'gem install bundler --conservative' 19 | system 'bundle check' or system! 'bundle install' 20 | 21 | puts "\n== Updating database ==" 22 | system! 'bin/rake db:migrate' 23 | 24 | puts "\n== Removing old logs and tempfiles ==" 25 | system! 'bin/rake log:clear tmp:clear' 26 | 27 | puts "\n== Restarting application server ==" 28 | system! 'bin/rake restart' 29 | end 30 | -------------------------------------------------------------------------------- /config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rake secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: 7a02c2bb6dc5185a72def57e1b00edde409a4aee352314cfb29c6bc908c236b3923819e0e3d18023c47625e420bffec7c172eac843ca3d48bb55d09bbb79dfaa 15 | 16 | test: 17 | secret_key_base: 3ddf42c90754b3d43a5fcecb3f55e38898119ccbe0ba444b88cdc9d3f884ffdb95f172127a63daea4658477d1fe798afd1eea3b1b290dead2c21f282fbc2b820 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 23 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | require 'fileutils' 4 | include FileUtils 5 | 6 | # path to your application root. 7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | chdir APP_ROOT do 14 | # This script is a starting point to setup your application. 15 | # Add necessary setup steps to this file. 16 | 17 | puts '== Installing dependencies ==' 18 | system! 'gem install bundler --conservative' 19 | system('bundle check') or system!('bundle install') 20 | 21 | # puts "\n== Copying sample files ==" 22 | # unless File.exist?('config/database.yml') 23 | # cp 'config/database.yml.sample', 'config/database.yml' 24 | # end 25 | 26 | puts "\n== Preparing database ==" 27 | system! 'ruby bin/rake db:setup' 28 | 29 | puts "\n== Removing old logs and tempfiles ==" 30 | system! 'ruby bin/rake log:clear tmp:clear' 31 | 32 | puts "\n== Restarting application server ==" 33 | system! 'ruby bin/rake restart' 34 | end 35 | -------------------------------------------------------------------------------- /test/controllers/books_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class BooksControllerTest < ActionController::TestCase 4 | setup do 5 | @book = books(:one) 6 | end 7 | 8 | test "should get index" do 9 | get :index 10 | assert_response :success 11 | end 12 | 13 | test "should create book" do 14 | assert_difference('Book.count') do 15 | post :create, params: { book: { description: @book.description, page_count: @book.page_count, title: @book.title } } 16 | end 17 | 18 | assert_response 201 19 | end 20 | 21 | test "should show book" do 22 | get :show, params: { id: @book } 23 | assert_response :success 24 | end 25 | 26 | test "should update book" do 27 | patch :update, params: { id: @book, book: { description: @book.description, page_count: @book.page_count, title: @book.title } } 28 | assert_response 200 29 | end 30 | 31 | test "should destroy book" do 32 | assert_difference('Book.count', -1) do 33 | delete :destroy, params: { id: @book } 34 | end 35 | 36 | assert_response 204 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | # This file is auto-generated from the current state of the database. Instead 3 | # of editing this file, please use the migrations feature of Active Record to 4 | # incrementally modify your database, and then regenerate this schema definition. 5 | # 6 | # Note that this schema.rb definition is the authoritative source for your 7 | # database schema. If you need to create the application database on another 8 | # system, you should be using db:schema:load, not running all the migrations 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). 11 | # 12 | # It's strongly recommended that you check this file into your version control system. 13 | 14 | ActiveRecord::Schema.define(version: 20151127182546) do 15 | 16 | create_table "books", force: :cascade do |t| 17 | t.string "title" 18 | t.integer "page_count" 19 | t.text "description" 20 | t.datetime "created_at", null: false 21 | t.datetime "updated_at", null: false 22 | end 23 | 24 | end 25 | -------------------------------------------------------------------------------- /config/initializers/swagger.rb: -------------------------------------------------------------------------------- 1 | class Swagger::Docs::Config 2 | def self.base_api_controller 3 | ActionController::API 4 | end 5 | end 6 | Swagger::Docs::Config.register_apis({ 7 | "1.0" => { 8 | :controller_base_path => "", 9 | # the extension used for the API 10 | :api_extension_type => :json, 11 | # the output location where your .json files are written to 12 | :api_file_path => "public", 13 | # the URL base path to your API 14 | :base_path => "http://api.booksapp.com", 15 | # if you want to delete all .json files at each generation 16 | :clean_directory => false, 17 | # add custom attributes to api-docs 18 | :attributes => { 19 | :info => { 20 | "title" => "Bookstore App", 21 | "description" => "This is an API for an online bookstore", 22 | "termsOfServiceUrl" => "https://github.com/switzersc/rails-5-api-tutorial", 23 | "contact" => "shelbyswitzer@gmail.com", 24 | "license" => "Apache 2.0", 25 | "licenseUrl" => "http://www.apache.org/licenses/LICENSE-2.0.html" 26 | } 27 | } 28 | } 29 | }) -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', path: "/Users/gwalchmai/Dev/webinar/rails" 4 | gem 'sprockets-rails', github: "rails/sprockets-rails" 5 | gem 'sprockets', github: "rails/sprockets" 6 | gem 'sass-rails', github: "rails/sass-rails" 7 | gem 'arel', github: "rails/arel" 8 | gem 'rack', github: "rack/rack" 9 | 10 | # Use sqlite3 as the database for Active Record 11 | gem 'sqlite3' 12 | # Use ActiveModel has_secure_password 13 | # gem 'bcrypt', '~> 3.1.7' 14 | 15 | # Use Unicorn as the app server 16 | # gem 'unicorn' 17 | 18 | # Use Capistrano for deployment 19 | # gem 'capistrano-rails', group: :development 20 | 21 | # Use ActiveModelSerializers to serialize JSON responses 22 | gem 'active_model_serializers', '~> 0.10.0.rc2' 23 | 24 | # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible 25 | # gem 'rack-cors' 26 | 27 | gem 'swagger-docs' 28 | 29 | group :development, :test do 30 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console 31 | gem 'byebug' 32 | gem 'rspec-rails' 33 | gem 'rails-controller-testing' 34 | end 35 | 36 | group :development do 37 | 38 | # Loading the listen gem enables an evented file system monitor. Check 39 | # https://github.com/guard/listen#listen-adapters if on Windows or *BSD. 40 | # gem 'listen', '~> 3.0.5' 41 | end 42 | 43 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 44 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 45 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports. 13 | config.consider_all_requests_local = true 14 | 15 | # Enable/disable caching. By default caching is disabled. 16 | if Rails.root.join('tmp/caching-dev.txt').exist? 17 | config.action_controller.perform_caching = true 18 | config.cache_store = :memory_store 19 | config.public_file_server.headers = { 20 | 'Cache-Control' => 'public, max-age=172800' 21 | } 22 | else 23 | config.action_controller.perform_caching = false 24 | config.cache_store = :null_store 25 | end 26 | 27 | 28 | # Don't care if the mailer can't send. 29 | config.action_mailer.raise_delivery_errors = false 30 | 31 | # Print deprecation notices to the Rails logger. 32 | config.active_support.deprecation = :log 33 | 34 | # Raise an error on page load if there are pending migrations. 35 | config.active_record.migration_error = :page_load 36 | 37 | 38 | # Raises error for missing translations 39 | # config.action_view.raise_on_missing_translations = true 40 | end 41 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require "rails" 4 | # Pick the frameworks you want: 5 | require "active_model/railtie" 6 | require "active_job/railtie" 7 | require "active_record/railtie" 8 | require "action_controller/railtie" 9 | require "action_mailer/railtie" 10 | require "action_view/railtie" 11 | # require "sprockets/railtie" 12 | require "rails/test_unit/railtie" 13 | 14 | # Require the gems listed in Gemfile, including any gems 15 | # you've limited to :test, :development, or :production. 16 | Bundler.require(*Rails.groups) 17 | 18 | module BooksApp 19 | class Application < Rails::Application 20 | # Settings in config/environments/* take precedence over those specified here. 21 | # Application configuration should go into files in config/initializers 22 | # -- all .rb files in that directory are automatically loaded. 23 | 24 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 25 | # Run "rake time:zones:all" for a time zone names list. Default is UTC. 26 | # config.time_zone = 'Central Time (US & Canada)' 27 | 28 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 29 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 30 | # config.i18n.default_locale = :de 31 | 32 | # Only loads a smaller set of middleware suitable for API only apps. 33 | # Middleware like session, flash, cookies can be added back manually. 34 | # Skip views, helpers and assets when generating a new resource. 35 | config.api_only = true 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |If you are the application owner check the logs for more information.
64 |Maybe you tried to change something you didn't have access to.
63 |If you are the application owner check the logs for more information.
65 |You may have mistyped the address or the page may have moved.
63 |If you are the application owner check the logs for more information.
65 |