$ rails --version
$ gem install rails
$ rails new <Application Name>
Step.2| Open the Gemfile and append the following lines.
$ vi Gemfile
gem ‘execjs’ gem ‘therubyracer’
$ bundle install
$ cd <Application Name> $ rails server
http://localhost:3000/
When you are setting portforwarding with rails4.2, localhost doesn't work by default. If you want to do port-forwarding, put the following option.
$ rails start -b 0.0.0.0
$ rails generate scaffold <Object Name>(Example)
$ rails generate scaffold scaffold_test
$ rake db:migrate
Now you have a page which maintains data stored in Sqlite DB.
$ rails generate controller <Controller Name> <Method(View)> <Method(View)>(Example)
$ rails generate controller Say hello goodbye
http://localhost:3000/say/hello/
#ref(): File not found: "CreateApplication_fig2.png" at page "HowToUse/RubyOnRails/4.1"
$ vi app/controller/<Controller file>
require 'open-uri' require 'json' res = open('<URL>') code, message = res.status if code == '200' @result = JSON.parse(res.read) end
$ vi app/view/<View file>
<table> <% @result.each do |data| %> <tr> <td><%= data['<Key#1>'] %></td> <td><%= data['<Key#2>'] %></td> </tr> <% end %> </table>
$ rvm install ruby-2.2.2
$ wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh
When you encounter error, you can use standalone edition with the following commands.
$ wget -qO- https://toolbelt.heroku.com/install.sh | bash $ echo 'PATH="/usr/local/heroku/bin:$PATH"' >> ~/.profile
$ heroku login
$ git clone <Git Repository>
or
$ cd <Ruby On Rails Project> $ git init $ git add . $ git commit -m "initial commit"
$ vi config/Gemfile
+gem 'pg' -gem 'sqlite3' +gem 'sqlite3', group: %w(test development), require: false +gem 'pg', group: %w(production), require: false
$ bundle install
$ vi db/database.yml
production: <<: *default - database: db/production.sqlite3 + adapter: pg + database: db/production.pg
$ heroku create <application name>
$ git push heroku master
S.Yatsuzuka