参考
手で準備
mkdir myapp && cd myapp
git init
bundle init
Gemfile
source 'https://rubygems.org'
gem 'sinatra'
gem 'haml'
gem 'sass'
gem 'coffee-script'
group :development do
gem 'foreman'
end
bundle install
プログラム準備
app.rb
require 'bundler/setup'
require 'sinatra'
require 'haml'
require 'sass'
require 'coffee-script'
get '/' do
@mes = 'こんにちは'
haml :index
end
Procfile
web: bundle exec ruby app.rb -p $PORT
views/index.haml
!!!
%meta(charset="UTF-8")
%title #{@title="たいとる"}
%script(src="//code.jquery.com/jquery-2.1.4.min.js")
//%script(src="myscript.js")
:sass
h1
color: red
:coffee
console.log('Hello!')
%h1 #{@title}
ローカル確認
foreman start
Herokuにpush
heroku create
git add -A && git commit -m "init"
git push heroku master
heroku open
padrino
padrino g project myapp \
-d activerecord -t rspec -e slim -s jquery
cd myapp
bundle
app/app.rb
module Myapp
class App < Padrino::Application
use ConnectionPoolManagement
register Padrino::Mailer
register Padrino::Helpers
enable :sessions
+ get '/' do
+ "Hello World"
+ end
end
end
管理画面
padrino g admin
bundle install
padrino rake ar:create
padrino rake ar:migrate
padrino rake seed #管理画面ログイン用のメールアドレス、パスワードを入力
padrino s -h 0.0.0.0
http://localhost:3000/admin/ にアクセスすると管理画面が表示される。
heroku用にpostgres対応
Gemfile
-gem 'sqlite3'
+group :development do
+ gem 'sqlite3'
+end
+group :production do
+ gem 'pg'
+end
bundle install
brew install postgresql
config/database.rb
-ActiveRecord::Base.configurations[:production] = {
- :adapter => 'sqlite3',
- :database => Padrino.root('db', 'myapp_production.db')
-}
+postgres = URI.parse(ENV['DATABASE_URL'] || '')
+
+ActiveRecord::Base.configurations[:production] = {
+ :adapter => 'postgresql',
+ :encoding => 'utf8',
+ :database => postgres.path[1..-1],
+ :username => postgres.user,
+ :password => postgres.password,
+ :host => postgres.host
+}
herokuにデプロイ
git init
git add -A && git commit -m "init"
heroku create
git push heroku master
heroku run rake ar:migrate
heroku run rake seed
heroku open