https://github.com/zoltan-nz/tutorial-builder-backend
Rails 5 API with jsonapi-resources
https://github.com/zoltan-nz/tutorial-builder-backend
Last synced: 7 months ago
JSON representation
Rails 5 API with jsonapi-resources
- Host: GitHub
- URL: https://github.com/zoltan-nz/tutorial-builder-backend
- Owner: zoltan-nz
- Created: 2016-06-11T03:58:01.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-15T07:26:53.000Z (over 8 years ago)
- Last Synced: 2025-01-22T02:46:04.859Z (9 months ago)
- Language: Ruby
- Size: 21.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## LOG
* Ruby 2.3
* Rails 5.0(On mac:)
$ gem install nokogiri -- --use-system-libraries
$ gem install railsCreate new API app
$ rails new tutorial-builder-backend --api --database=postgresql --skip-javascript --skip-sprockets -d
Add jsonapi-resources
$ gem 'jsonapi-resources', '^0.8.0.beta2'
Only the new beta version is compatible with rails v5 rc1.
$ rails db:create
Create resource
$ rails g jsonapi:resource sandbox
Create model
rails g model sandbox name source
Update ApplicationController
class ApplicationController < JSONAPI::ResourceController
endCreate SandboxesController
$ rails g controller sandboxes
class SandboxesController < ApplicationController
endAdd route
Rails.application.routes.draw do
jsonapi_resources :sandboxes
endRun migration
rails db:migrate
Activate CORS
* Uncomment gem 'rack-cors',
* `bundle update`
* Uncomment config/initializers/corsRails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end### Implementing tutorial, lesson and step models
$ rails g model tutorial name lessons:hasMany
$ rails g jsonapi:resource tutorial## Reading
http://blog.arkency.com/2016/02/how-and-why-should-you-use-json-api-in-your-rails-api/
https://github.com/cerebris/jsonapi-resources
http://edgeguides.rubyonrails.org/api_app.html
https://blog.codeship.com/building-a-json-api-with-rails-5/