LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

5分で笑えるWebサービスイベント資料

Last updated at Posted at 2015-10-14

事前準備

  • Twilioアカウント取得
  • Herokuアカウント取得とアプリケーション作成
  • ngrok入れておくと便利
brew install ngrok

Sinatraセットアップ

Gemfile

source "https://rubygems.org"
gem 'pg'
gem 'rake'
gem 'sinatra'
gem 'sinatra-activerecord'
gem 'activerecord'

gem 'twilio-ruby', '~> 4.2.1'
gem "shotgun"

Rakefile

require './app'
require 'sinatra/activerecord/rake'

config/database.yml

default: &default           
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  <<: *default
  database: iloveyou_development

test:
  <<: *default
  database: iloveyou_test

app.rb

  require 'sinatra'
  require 'sinatra/activerecord'
  require 'twilio-ruby

_

インストール

brew install postgresql
bundle install  --path=vendor/bundle
bundle exec rake db:create

テーブル設定

bundle exec rake db:create_migration NAME=create_calls
  • マイグレーションファイル
class CreateCalls < ActiveRecord::Migration
  def self.up
    create_table :calls do |t| 
      t.string :from_name
      t.string :to_name
      t.string :tel
      t.text :message
      t.integer :status
      t.timestamps null: false
    end 
  end 
  def self.down
    drop_table :calls
  end 
end
  • マイグレーション
bundle exec rake db:migrate

実装

bundle exec shotgun app.rb
  • Twilioをつなぐ場合
ngrok  [ポート番号]

Heroku設定

  • アプリケーション作成
  • DB作成
  • 環境変数設定
  • DB作成とマイグレーション
 heroku run rake db:create
 heroku run rake db:migrate
  • ログチェック
heroku logs --tail
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up