HerokuでRuby on Rails
HerokuでRailsアプリを動かしてみる。
Herokuについてはググって。
上記でクレカ番号入れることなく、メアドだけでアカウント作れる。
HerokuではGit使うから下記でも見てGit環境つくって。
下記を参考にサンプルアプリ作る。
上記サンプルのGemfileを編集する。
source 'https://rubygems.org' ruby '2.0.0' # 追加! # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.1.1' # Use sqlite3 as the database for Active Record group :development do # 追加! gem 'sqlite3' end # 追加! # Use SCSS for stylesheets gem 'sass-rails', '~> 4.0.3' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .js.coffee assets and views gem 'coffee-rails', '~> 4.0.0' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use unicorn as the app server # gem 'unicorn' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development # Use debugger # gem 'debugger', group: [:development, :test] # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin] group :production do # 追加! gem 'pg', '0.15.1' # 追加! gem 'rails_12factor', '0.0.2' # 追加! end # 追加!
Gemfile変更したらproduction環境用以外のgemを反映。
C:\>cd C:\rubyWorkspace\scaffolding C:\rubyWorkspace\scaffolding> bundle install --without production
Gitのローカルリポジトリ作成。
C:\rubyWorkspace\scaffolding>git init Initialized empty Git repository in C:/rubyWorkspace/scaffolding/.git/ C:\rubyWorkspace\scaffolding>git add . C:\rubyWorkspace\scaffolding>git commit -m "first commit"
Herokuアカウント作ってHerokuにWebでログインしたら
https://toolbelt.heroku.com/download/windows
からHeroku Toolbeltをダウンロードしてインストールする。
C:\rubyWorkspace\scaffolding>heroku login Enter your Heroku credentials. Email: xxx@yyy Password (typing will be hidden): Could not find an existing public key. Would you like to generate one? [Yn] Y Generating new SSH public key. Uploading SSH public key C:/Users/[USER]/.ssh/id_rsa.pub... done Authentication successful. C:\rubyWorkspace\scaffolding>heroku keys:add Found existing public key: C:/Users/[USER]/.ssh/id_rsa.pub Uploading SSH public key C:/Users/[USER]/.ssh/id_rsa.pub... done
なんかよくわからん公開鍵ができたっぽい。
できた鍵をHerokuに登録もした。
どきどき。
C:\rubyWorkspace\scaffolding>heroku create Creating damp-crag-9947... done, stack is cedar http://damp-crag-9947.herokuapp.com/ | git@heroku.com:damp-crag-9947.git Git remote heroku added C:\rubyWorkspace\scaffolding>git remote heroku C:\rubyWorkspace\scaffolding>git remote -v heroku git@heroku.com:damp-crag-9947.git (fetch) heroku git@heroku.com:damp-crag-9947.git (push)
どきどき。
C:\rubyWorkspace\scaffolding>git push heroku master ssh: connect to host heroku.com port 22: Bad file number fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
ちくしょーーーーーーーーーーー!!!!!!!
Githubは普通にpushできるのに。。。
URLは「git@」から始まるのはダメなんだな!Githubも「git@」から始まる書き方じゃダメだったし!
# この書き方の意味はわからない。。。
C:\rubyWorkspace\scaffolding>git remote set-url heroku https://www.heroku.com/damp-crag-9947.git C:\rubyWorkspace\scaffolding>git push heroku master fatal: repository 'https://www.heroku.com/damp-crag-9947.git/' not found
「heroku open」って打ちたいお(´;ω;`)
参考:
http://exfreeter.hatenablog.com/entry/2013/12/09/235902
「heroku The remote end hung up unexpectedly」で検索。
http://d.hatena.ne.jp/nayuko22/20110920/p1
http://daipresents.com/2012/heroku%E3%81%A7push%E3%81%97%E3%82%88%E3%81%86%E3%81%A8%E3%81%97%E3%81%9F%E3%82%89permission-denied%E3%81%A8%E3%81%AA%E3%81%A3%E3%81%A6%E3%81%97%E3%81%BE%E3%81%86/
ここで解決しそう?
http://roguer.info/2011/11/11/4322/