$ 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/
#ref(): File not found: "CreateApplication_fig1.png" at page "HowTOUse/RubyOnRails/4.2"
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
#ref(): File not found: "CreateSample_fig1.png" at page "HowTOUse/RubyOnRails/4.2"
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.2"
$ 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>
$ rails g migration <Migration Script Name>
(Example)
$ rails g migration AddColumnUsers
$ vi db/migrate/<Migration Script File Name>
(Example)
$ rails g migration db/migrate/20150927000024_add_column_workorders.rb
class AddColumnWorkorders < ActiveRecord::Migration def change add_column :<table name>, :<column name>, :<data type> remove_column :<table name>, :<column name> end end
$ rails db:migrate
$ vi app/views/<table>/index.html.erb
$ vi app/views/<table>/_form.html.erb
<%= f.label :<column> %> <%= f.text_field :<column> %>
$ vi app/controller/<table name>_controller.rb
def create attr = params.require(:<table name>).permit(:<column name>) @<table name> = <table name>.new(attr)
$ rake test
S.Yatsuzuka