Ruby on Rails の基礎
                     @jishiha




13年1月10日木曜日
参考
              • Ruby on Rails の基礎 byドットインス
               トール http://dotinstall.com/lessons/
               basic_rails
              • Ruby on Rails をこれから始める人への
               おすすめ本やおすすめ情報 http://
               blog.champierre.com/963


13年1月10日木曜日
環境構築

              • Mac OS X 10.8
              • Mac OS X 10.8 Mountain Lion に Ruby on
                Rails 環境をセットアップする http://
                blog.champierre.com/961




13年1月10日木曜日
MVC?

              • Model データ
              • View 見た目
              • Controller MとVを結ぶ処理


13年1月10日木曜日
新しいプロジェクトの作成



              • rails new blog
              • echo "rvm use ruby-1.9.3" > blog/.rvmrc
              • cd blog


13年1月10日木曜日
ファイル構成


              • cd blog
              • subl .


13年1月10日木曜日
Web サーバーを起動

              • rails s (WEBrick)
              • open http://localhost:3000
              • 本当は pow のほうがオススメ http://
               pow.cx/




13年1月10日木曜日
scaffold

              • rails g scaffold Post title:string content:text
              • bundle exec rake db:migrate
              • open http://localhost:3000/posts


13年1月10日木曜日
DB(sqlite)の確認


              • SQLite Manager https://addons.mozilla.org/
                ja/firefox/addon/sqlite-manager/




13年1月10日木曜日
URLの設定


              • config/routes.rb を編集
              • root :to => 'posts#index' を追加


13年1月10日木曜日
rails console


              • rails c
              • >> Post.all


13年1月10日木曜日
Controllerの編集

              • respond_to do |format|... は削除
              • def create/update/destroy では format.html
                {...} の {} 内を残す




13年1月10日木曜日
Viewの確認
              • app/views/posts/index.html.erb
              • ファイル名がアクション名に対応
              • @付き変数にアクセスできる
              • View の外枠は views/layouts/
                application.html.erb で定義


13年1月10日木曜日
Rails と Sinatra の違い

              • link_to image_to などのヘルパーが便利
              • <%= f.submit '投稿', disable_with: "処理
                中..." %>




13年1月10日木曜日
Heroku に deploy(1)
              • Gemfile の編集
              group :development do
               gem 'sqlite3'
              end

              group :production do
               gem 'pg'
              end

13年1月10日木曜日
Heroku に deploy(2)

              • bundle install
              • git init
              • git add .
              • git commit -a
              • /usr/local/heroku/bin/heroku create

13年1月10日木曜日
Heroku に deploy(3)

              • git push heroku master
              • /usr/local/heroku/bin/heroku run rake
                db:migrate
              • /usr/local/heroku/bin/heroku open


13年1月10日木曜日
つづく(かも)



13年1月10日木曜日

Railsの基礎

  • 1.
    Ruby on Railsの基礎 @jishiha 13年1月10日木曜日
  • 2.
    参考 • Ruby on Rails の基礎 byドットインス トール http://dotinstall.com/lessons/ basic_rails • Ruby on Rails をこれから始める人への おすすめ本やおすすめ情報 http:// blog.champierre.com/963 13年1月10日木曜日
  • 3.
    環境構築 • Mac OS X 10.8 • Mac OS X 10.8 Mountain Lion に Ruby on Rails 環境をセットアップする http:// blog.champierre.com/961 13年1月10日木曜日
  • 4.
    MVC? • Model データ • View 見た目 • Controller MとVを結ぶ処理 13年1月10日木曜日
  • 5.
    新しいプロジェクトの作成 • rails new blog • echo "rvm use ruby-1.9.3" > blog/.rvmrc • cd blog 13年1月10日木曜日
  • 6.
    ファイル構成 • cd blog • subl . 13年1月10日木曜日
  • 7.
    Web サーバーを起動 • rails s (WEBrick) • open http://localhost:3000 • 本当は pow のほうがオススメ http:// pow.cx/ 13年1月10日木曜日
  • 8.
    scaffold • rails g scaffold Post title:string content:text • bundle exec rake db:migrate • open http://localhost:3000/posts 13年1月10日木曜日
  • 9.
    DB(sqlite)の確認 • SQLite Manager https://addons.mozilla.org/ ja/firefox/addon/sqlite-manager/ 13年1月10日木曜日
  • 10.
    URLの設定 • config/routes.rb を編集 • root :to => 'posts#index' を追加 13年1月10日木曜日
  • 11.
    rails console • rails c • >> Post.all 13年1月10日木曜日
  • 12.
    Controllerの編集 • respond_to do |format|... は削除 • def create/update/destroy では format.html {...} の {} 内を残す 13年1月10日木曜日
  • 13.
    Viewの確認 • app/views/posts/index.html.erb • ファイル名がアクション名に対応 • @付き変数にアクセスできる • View の外枠は views/layouts/ application.html.erb で定義 13年1月10日木曜日
  • 14.
    Rails と Sinatraの違い • link_to image_to などのヘルパーが便利 • <%= f.submit '投稿', disable_with: "処理 中..." %> 13年1月10日木曜日
  • 15.
    Heroku に deploy(1) • Gemfile の編集 group :development do gem 'sqlite3' end group :production do gem 'pg' end 13年1月10日木曜日
  • 16.
    Heroku に deploy(2) • bundle install • git init • git add . • git commit -a • /usr/local/heroku/bin/heroku create 13年1月10日木曜日
  • 17.
    Heroku に deploy(3) • git push heroku master • /usr/local/heroku/bin/heroku run rake db:migrate • /usr/local/heroku/bin/heroku open 13年1月10日木曜日
  • 18.