2014/08/18

ruby on rails

bundle install
==>Install the modules include in the gemfile.
Unless you specify a version number to the gem command, Bundler will automatically install the latest version of the gem.
bundle update===>update!!


・deployの準備
bundle install --without production
group :production do
    gem 'pg'
    gem 'rails_12factor'
end

・@なになに。。
Once the @users variable is defined, the controller calls the view (Step 6), shown in Listing 2.6. Variables that start with the @ sign, called instance variables, are automatically available in the view;

・rails new sample_app --skip-test-unit
===>not to create test directory

・rails generate controller StaticPages home help --no-test-framework
===>「home help」MVCセットで2つ作る

・rails generate rspec:install
bundle exec rspec spec/requests/..rb==>実行、red->green->refactor

・JetBrains:
==>alt+ctr+s =->editerのところでline番号を表示する。

・<% provide(:title, 'Home') %>
Rails should call the provide function and associate the string ’Home’ with the label :title.
<%= yield(:title) %>
    yield==->自分で定義したブロック付きメソッドでブロックを呼び出すときに使います

・application.html.erb:
<%= yield %>
==>This code is responsible for inserting the contents of each page into the layout. It’s not important to know exactly how this works; what matters is that using this layout ensures that, for example, visiting the page /static_pages/home converts the contents of home.html.erb to HTML and then inserts it in place of <%= yield %>.


・first_name + " " + last_name
===
"#{first_name} #{last_name}"

・# Single-quoted strings don't allow interpolation

・Note that Ruby functions have an implicit return
meaning they return the last statement evaluated

・a = [42, 8, 17]
a[-1]==>17
a.sort
a.sort!===>a!
a.push(6)
a << 7
a << "foo" << "bar"

a.split--->array になる
array.join-->stringになる


(0..9).to_a
a[0..2]


・|i|
==>The vertical bars around the variable name in |i| are Ruby syntax for a block variable