tng-rails-api.md#

Setup#

md app-dir
cd app-dir
rails new . --api --database=postgresql/(leave for sqlite)
rails db:create # makes empty DB
rails s -p 3001 # so that we can test with other port for SPA

Gemfile#

gem 'bcrypt'    # open this

config/application.rb#

uncomment > require "sprockets/railtie"     # something for Asset pipeline

run bundle install to bring in bcrypt

Sprockets is a Ruby library for compiling and serving web assets. It features declarative dependency management for JavaScript and CSS assets, as well as a powerful preprocessor pipeline that allows you to write assets in languages like CoffeeScript, Sass and SCSS.
The asset pipeline is technically no longer a core feature of Rails 4, it has been extracted out of the framework into the sprockets-rails gem.

Sprockets is a Ruby library for compiling and serving web assets. Sprockets allows to organize an application’s JavaScript files into smaller more manageable chunks that can be distributed over a number of directories and files. It provides structure and practices on how to include assets in our projects.

Using directives at the start of each JavaScript file, Sprockets can determine which files a JavaScript file depends on. When it comes to deploying your application, Sprockets then uses these directives to turn your multiple JavaScript files into a single file for better performance.

/app/assets/javascripts/application.js
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require_tree .

application.js file is known as a manifest and it’s managed internally by Sprockets. When a request comes in for this file Sprockets looks at the manifest and compiles together every file that is mentioned in it and includes their contents before any code in this file. Sprockets will search the loadpath for this file and, in this case, load it from the jquery-rails engine’s vendor/asset/javascripts directory.

Create data#

> rails g migration CreateUsers

Then add model to db\migrate\<new-file-created>

The 'password_digest' field is required for bcrypt
 rails g migration CreateLists