Hello World from OSS Silicon Valley


HowToUse/RubyOnRails/4.2/Heroku/2015


  • The added line is THIS COLOR.
  • The deleted line is THIS COLOR.
#contents

*Prerequisite [#z427d905]
-Ubuntu Server installation (You can refer [[Overall/UbuntuServer]])
-Ruby On Rails installation (You can refer [[Overall/RubyOnRails]])
-Ubuntu Server 14.04 installation (You can refer [[HowToUse/UbuntuServer/14.04]])
-RVM installation (You can refer [[HowToUse/RVM/1.25]])
-Ruby On Rails installation (You can refer [[HowToUse/RubyOnRails/4.1]])
-PostgreSQL installation (You can refer [[HowToUse/PostgreSQL/9.3]])
-Ruby On Rails with PostgreSQL connection (You can refer [[HowToUse/RubyOnRails/4.2/PostgreSQL/9.3]])

*Install&Setup [#re66614c]
**Prepare Heroku's development environment [#ze65401f]
:Step.1|
Access to Heroku's web site.

#ref(CreateAccount_fig1.png,,500x266,)

:Step.2|
Login the system.

#ref(CreateAccount_fig2.png,,500x266,)

#ref(CreateAccount_fig3.png,,500x266,)

:Step.3|
Click the Ruby's icon, and you will see the instruction how to install Heroku Toolbelt.

#ref(CreateAccount_fig4.png,,500x266,)

:Step.4|
Execute the following commands.

 $ gem install bundler

:Step.5|
Download Heroku Toolbelt from the link in web page.


*HowToUse [#x70f7da3]
*HowToUse [#qe563e1e]
**Create rails project [#h6e960a7]

:Step.1|
Login to Heroku server.

 $ heroku login

:Step.2|
Prepare sample project from GitHub.
Change directory of your application which uses PostgreSQL not Sqlite.
(You can refer [[HowToCreate/RubyOnRails/4.2/PostgreSQL/9.3]] about how to create Rails Application with )

 $ git clone https://github.com/heroku/ruby-getting-started.git
 $ cd ruby-getting-started


:Step.3|
Create new project in Heroku space.

 $ heroku create

You can destroy app with the following command.

 $ heroku apps:destroy --app <App name>


:Step.4|
Deploy the sample project to Heroku server.
Prepare sample project.

 $ git push heroku master
 $ bundle exec rake assets:precompile
 $ git init
 $ git add .
 $ git commit -m "initial check-in"

When you don't precompile the modules, Heroku sometimes doesn't recognize stylesheet as expected. [#dc1c44b6]

Then you will see the following window from the URL displayed in the terminal.

#ref(CreateApps_fig1.png,,500x266,)

:Step.5|
Launch instance.
If your application create image file and you want to display it in your application, add the following line in config/application.rb

 $ heroku open
 $ vi config/application.rb

:Step.6|
Check server log.
 config.serve_static_assets = true

 $ heroku logs --tail
You can read [[here:https://devcenter.heroku.com/articles/rails-4-asset-pipeline]] for detail

:Step.6|
Enter Ctrl-C, and define Procfile.
Deploy project into Heroku server.

 $ vi Procfile
 $ git push heroku master

 web: bundle exec puma -C config/puma.rb

:Step.7|
Check how many dynos is launched.
**Configure rails project [#h6e960a7]
:Step.1|
Migrate database

 $ heroku ps
 $ heroku run rake db:migrate

:Step.8|
Execute the bundle install
Then you can access your application as expected. You can create record to the database in Heroku server.

 $ bundle install
#ref(CreateApps_fig2.png,,500x266,)

#ref(CreateApps_fig3.png,,500x266,)

:Step.9|
Run the application locally.
:Step.2|
You can setup environment variable as needed. For example, in case you want to use third party's authentification service, it is recommended to set upt those in environment variable so that internet user can't see it.

 $ bundle exec rake db:create db:migrate
 $ heroku config:set GITHUB_KEY="xxx"
 $ heroku config:set GITHUB_SECRET="xxx"

:Step.10
Create/migrate database.
:Step.3|
Load seed data

 $ rake db:create db:migrate
 $ heroku run rake db:seed

:Step.11
Launch local instance.

 $ heroku local web
**Upload module from other work environment [#m787dc94]

Then you can access to http://localhost:5000/
:Step.1|
Login to Heroku environment.

 $ heroku login

:Step.2|
Add remote path.

 $ heroku git:remote -a <application ID>

:Step.3|
Push modules.

 $ git push heroku master

In case you encounter the problem on "Permission denied", you can refer [[This Posting:http://stackoverflow.com/questions/12206779/git-push-heroku-master-permission-denied-publickey-fatal-the-remote-end-hung]].

 $ heroku keys:add ~/.ssh/id_rsa.pub



**Task Scheduller [#jcadae67]

:Step.1|
Create task file.

:Step.2|
Test task.

(local execution)
 $ rake <task name>

(Execution in Heroku)
 $ heroku run rake <task name>

:Step.3|
Register task in Heroku.

https://scheduler.heroku.com/dashboard


*Author [#r1ccd722]
S.Yatsuzuka