Ionic + Rails API (JPN) Flashcards
Rails: Create the Rails Backend
$rails new agenda_backend -T
Rails: Create the Person Model
$rails g model person name phone
Rails: Seed the test database seed.rb
Person.create(name: ‘Laura’, phone: ‘1800-3137977’)
Person.create(name: ‘Jeniffer’, phone: ‘1800-123456’)
Person.create(name: ‘Tom’, phone: ‘1800-654321’)
Rails: Add routes to Persons
namespace :api, constrains: { format: :json } do
get ‘people’ => ‘agenda#all’
end
Rails: Install Rack-Cors Gem (CORS = Cross origin reference sharing)
gem ‘rack-cors’, :require => ‘rack/cors’
Rails: Config the CORS middleware layer config > application.rb
config.middleware.use Rack::Cors do allow do origins '*' resource '*', :headers => :any, :methods => [ :get, :post, :options, :delete] end end
Rails: Install Serializer Gem
gem ‘active_model_serializers’
Rails: Generate serializer
$rails g serializer person
Rails: Config Serializer app > serializers > person_serializer.rb
class PersonSerializer
Rails: Generate API Controller
$rails g controller api/agenda all –no-helper – no-assets
Rails: Configure API Controller
module Api class Api::AgendaController
Rails: API JSON Test
$ rails s
$ curl -X GET ‘http://localhost:3000/api/people’
Ionic: Generate ionic app
$ ionic start agenda blank
Ionic: Add iOS/Android platform
$ ionic platform add ios
$ ionic platform add android
Ionic: Config People_Controller.js www > js > controllers > people_controller.js
(function() {
var app = angular.module(‘peopleController’, []);
app.controller(‘PeopleController’,
function($scope, $http) {
$scope.names = [‘Jeniffer’, ‘Jackson’, ‘Jose’];
} ); })