git clone git@github.com:womanonrails/angular2-example-app.git
cd angular2-example-app
npm install
npm start
- Gemset:
.ruby-version
.ruby-gemset
gem install rails
rails new angular_api_app --api
cd angular_api_app
- Initial commit for Rails
- Modify Rails inflections
# config/initializers/inflections.rb
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.irregular 'hero', 'heroes'
end
-
rails g scaffold hero name:string:uniq
-
Update migration
# db/migrate
class CreateHeroes < ActiveRecord::Migration[5.0]
def change
create_table :heroes do |t|
t.string :name, null: false
t.timestamps
end
add_index :heroes, :name, unique: true
end
end
-
rails db:migrate
-
Prepare seeds
# db/seed.rb
Hero.create([
{ name: 'Jason' },
{ name: 'Tim' },
{ name: 'Zach' },
{ name: 'Matt' },
])
rails db:seed
rails server -p 3002
gem 'rack-cors'
bundle install
- Prepare Cors
# config/initializers/cors.rb
# Be sure to restart your server when you modify this file.
# Avoid CORS issues when API is called from the frontend app.
# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests.
# Read more: https://github.com/cyu/rack-cors
Rails.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
Let's finished this tutorial