※自己責任で。
◆Gemset作成
rvm gemset create use_rails4
◆Gemset切り替え
rvm gemset use use_rails4
rvm gemset list
-----
global
=> use_rails4
-----
◆bundlerインストール
gem install bundler
-----
gem install bundler
Fetching: bundler-1.1.3.gem (100%)
Successfully installed bundler-1.1.3
1 gem installed
-----
◆作業用ディレクトリ作成
mkdir rails4sample
cd rails4sample
◆Gemfile作成
vi Gemfile
-----
# Bundle edge Rails instead:
gem 'rails', :git => 'git://github.com/rails/rails.git'
-----
◆Gemインストール
bundle install
-----
Fetching git://github.com/rails/rails.git
remote: Counting objects: 294608, done.
remote: Compressing objects: 100% (74069/74069), done.
remote: Total 294608 (delta 228965), reused 281889 (delta 217753)
Receiving objects: 100% (294608/294608), 40.09 MiB | 30 KiB/s, done.
Resolving deltas: 100% (228965/228965), done.
Fetching gem metadata from https://rubygems.org/.......
Installing rake (0.9.2.2)
Installing i18n (0.6.0)
Installing multi_json (1.2.0)
Installing tzinfo (0.3.32)
Using activesupport (4.0.0.beta) from git://github.com/rails/rails.git (at master)
Installing builder (3.0.0)
Using activemodel (4.0.0.beta) from git://github.com/rails/rails.git (at master)
Installing erubis (2.7.0)
Installing journey (1.0.3)
Installing rack (1.4.1)
Installing rack-cache (1.2)
Installing rack-test (0.6.1)
Using actionpack (4.0.0.beta) from git://github.com/rails/rails.git (at master)
Installing mime-types (1.18)
Installing polyglot (0.3.3)
Installing treetop (1.4.10)
Installing mail (2.4.4)
Using actionmailer (4.0.0.beta) from git://github.com/rails/rails.git (at master)
Installing arel (3.0.2)
Using activerecord (4.0.0.beta) from git://github.com/rails/rails.git (at master)
Using bundler (1.1.3)
Installing hike (1.2.1)
Installing json (1.6.6) with native extensions
Installing rdoc (3.12)
Installing thor (0.14.6)
Using railties (4.0.0.beta) from git://github.com/rails/rails.git (at master)
Installing tilt (1.3.3)
Installing sprockets (2.3.2)
Installing sprockets-rails (1.0.0)
Using rails (4.0.0.beta) from git://github.com/rails/rails.git (at master)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:
<= 1.8.6 : unsupported
= 1.8.7 : gem install rdoc-data; rdoc-data --install
= 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!
-----
◆インストールGem一覧
bundle show
-----
Gems included by the bundle:
* actionmailer (4.0.0.beta)
* actionpack (4.0.0.beta)
* activemodel (4.0.0.beta)
* activerecord (4.0.0.beta)
* activesupport (4.0.0.beta)
* arel (3.0.2)
* builder (3.0.0)
* bundler (1.1.3)
* erubis (2.7.0)
* hike (1.2.1)
* i18n (0.6.0)
* journey (1.0.3)
* json (1.6.6)
* mail (2.4.4)
* mime-types (1.18)
* multi_json (1.2.0)
* polyglot (0.3.3)
* rack (1.4.1)
* rack-cache (1.2)
* rack-test (0.6.1)
* rails (4.0.0.beta a9398a7)
* railties (4.0.0.beta)
* rake (0.9.2.2)
* rdoc (3.12)
* sprockets (2.3.2)
* sprockets-rails (1.0.0)
* thor (0.14.6)
* tilt (1.3.3)
* treetop (1.4.10)
* tzinfo (0.3.32)
-----
◆Railsアプリ作成
bundle exec rails new ./
-----
Using --skip-bundle from /Users/*****/.railsrc
exist
create README.rdoc
create Rakefile
create config.ru
create .gitignore
conflict Gemfile
Overwrite /Users/*****/labo/rails4sample/Gemfile? (enter "h" for help) [Ynaqdh] a
force Gemfile
create app
create app/assets/images/rails.png
create app/assets/javascripts/application.js
create app/assets/stylesheets/application.css
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/mailers
create app/models
create app/views/layouts/application.html.erb
create app/mailers/.gitkeep
create app/models/.gitkeep
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/secret_token.rb
create config/initializers/session_store.rb
create config/initializers/wrap_parameters.rb
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create doc
create doc/README_FOR_APP
create lib
create lib/tasks
create lib/tasks/.gitkeep
create lib/assets
create lib/assets/.gitkeep
create log
create log/.gitkeep
create public
create public/404.html
create public/422.html
create public/500.html
create public/favicon.ico
create public/index.html
create public/robots.txt
create script
create script/rails
create test/fixtures
create test/fixtures/.gitkeep
create test/functional
create test/functional/.gitkeep
create test/integration
create test/integration/.gitkeep
create test/unit
create test/unit/.gitkeep
create test/performance/browsing_test.rb
create test/test_helper.rb
create tmp/cache
create tmp/cache/assets
create vendor/assets/javascripts
create vendor/assets/javascripts/.gitkeep
create vendor/assets/stylesheets
create vendor/assets/stylesheets/.gitkeep
-----
◆Gemfile編集
Gemfile
-----
source 'https://rubygems.org'
# Bundle edge Rails instead:
gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sprockets-rails', :git => 'git://github.com/rails/sprockets-rails.git'
# gem 'sass-rails', '~> 3.2.3'
# gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# ----- Add ----- #
# For Heroku
group :production do
gem 'pg'
gem 'thin'
end
# Utility
gem 'kaminari'
gem 'html5_validators'
gem 'active_decorator'
# OmniAuth
gem 'omniauth-github'
gem 'omniauth-twitter'
# ----- / Add ----- #
-----
◆Gemインストール
bundle install --without production
◆Railsバージョン
rails -v
-----
Rails 4.0.0.beta
-----
◆Topコントローラ作成
rails g controller top index
-----
create app/controllers/top_controller.rb
route get "top/index"
invoke erb
create app/views/top
create app/views/top/index.html.erb
invoke test_unit
create test/functional/top_controller_test.rb
invoke helper
create app/helpers/top_helper.rb
invoke test_unit
create test/unit/helpers/top_helper_test.rb
invoke assets
invoke js
create app/assets/javascripts/top.js
invoke css
create app/assets/stylesheets/top.css
-----
◆スキャフォールド作成
rails g scaffold Item name description:text
-----
invoke active_record
create db/migrate/20120405110318_create_items.rb
create app/models/item.rb
invoke test_unit
create test/unit/item_test.rb
create test/fixtures/items.yml
route resources :items
invoke scaffold_controller
create app/controllers/items_controller.rb
invoke erb
create app/views/items
create app/views/items/index.html.erb
create app/views/items/edit.html.erb
create app/views/items/show.html.erb
create app/views/items/new.html.erb
create app/views/items/_form.html.erb
invoke test_unit
create test/functional/items_controller_test.rb
invoke helper
create app/helpers/items_helper.rb
invoke test_unit
create test/unit/helpers/items_helper_test.rb
invoke assets
invoke js
create app/assets/javascripts/items.js
invoke css
create app/assets/stylesheets/items.css
invoke css
create app/assets/stylesheets/scaffold.css
-----
◆config/routes.rb編集
-----
root :to => 'top#index'
-----
◆マイグレーション
rake db:migrate
-----
== CreateItems: migrating ====================================================
-- create_table(:items)
-> 0.0017s
== CreateItems: migrated (0.0026s) ===========================================
-----
◆index.htmlリネーム
public/index.html
↓
public/_____index.html
◆ローカルサーバ起動
rails s
-----
=> Booting WEBrick
=> Rails 4.0.0.beta application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-04-05 20:05:10] INFO WEBrick 1.3.1
[2012-04-05 20:05:10] INFO ruby 1.9.3 (2012-02-16) [x86_64-darwin10.8.0]
[2012-04-05 20:05:10] INFO WEBrick::HTTPServer#start: pid=8202 port=3000
-----
◆アクセス確認
http://0.0.0.0:3000/
http://0.0.0.0:3000/items
◆エラー対処
app/views/items/_form.html.erb
20行目コメントアウト
-----
<%#= f.text_area :description %>
-----
↓下記エラーとなる
「ActionView::Template::Error (undefined local variable or method `options' for #<ActionView::Helpers::Tags::TextArea:0x00000102ce4de0>):」
◆Gitリポジトリ作成
git init
-----
Initialized empty Git repository in /Users/*****/labo/rails4sample/.git/
-----
◆プリコンパイル
rake assets:precompile RAILS_ENV=production
-----
/Users/*****/.rvm/rubies/ruby-1.9.3-p125/bin/ruby /Users/*****/.rvm/gems/ruby-1.9.3-p125@use_rails4/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
-----
◆Gitコミット
git add . && git commit -m "first commit"
◆Gitステータス確認
git status
-----
# On branch master
nothing to commit (working directory clean)
-----
◆Heroku Gemインストール
gem install heroku
-----
Fetching: netrc-0.7.1.gem (100%)
Fetching: rest-client-1.6.7.gem (100%)
Fetching: launchy-2.1.0.gem (100%)
Fetching: rubyzip-0.9.6.1.gem (100%)
Fetching: heroku-2.23.0.gem (100%)
Successfully installed netrc-0.7.1
Successfully installed rest-client-1.6.7
Successfully installed launchy-2.1.0
Successfully installed rubyzip-0.9.6.1
Successfully installed heroku-2.23.0
5 gems installed
-----
◆Herokuアプリ作成
heroku create rails4sample01
-----
Creating rails4sample01... done, stack is bamboo-mri-1.9.2
http://rails4sample01.heroku.com/ | git@heroku.com:rails4sample01.git
Git remote heroku added
-----
◆Herokuリモートリポジトリ
git remote -v
-----
heroku git@heroku.com:rails4sample01.git (fetch)
heroku git@heroku.com:rails4sample01.git (push)
-----
◆Herokuプッシュ
git push heroku master
-----
Counting objects: 100, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (87/87), done.
Writing objects: 100% (100/100), 101.17 KiB, done.
Total 100 (delta 6), reused 0 (delta 0)
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Detected Rails is not set to serve static_assets
Installing rails3_serve_static_assets... done
-----> Configure Rails 3 to disable x-sendfile
Installing rails3_disable_x_sendfile... done
-----> Configure Rails to log to stdout
Installing rails_log_stdout... done
-----> Gemfile detected, running Bundler version 1.0.7
Unresolved dependencies detected; Installing...
Using --without development:test
! Gemfile.lock will soon be required
! Check Gemfile.lock into git with `git add Gemfile.lock`
! See http://devcenter.heroku.com/articles/bundler
You have modified your Gemfile in development but did not check
the resulting snapshot (Gemfile.lock) into version control
You have added to the Gemfile:
* source: git://github.com/rails/sprockets-rails.git (at master)
* source: git://github.com/rails/rails.git (at master)
* source: rubygems repository https://rubygems.org/
* rails
* sqlite3
* sprockets-rails
* uglifier (>= 1.0.3)
* jquery-rails
* pg
* thin
* kaminari
* html5_validators
* active_decorator
* omniauth-github
* omniauth-twitter
You have changed in the Gemfile:
* rails from `git://github.com/rails/rails.git (at master)` to `no specified source`
* sprockets-rails from `git://github.com/rails/sprockets-rails.git (at master)` to `no specified source`
FAILED: http://devcenter.heroku.com/articles/bundler
! Heroku push rejected, failed to install gems via Bundler
To git@heroku.com:rails4sample01.git
! [remote rejected] master -> master (pre-receive hook declined)
-----
※エラー:Herokuにはpush出来ない
◆GitHubリポジトリ作成
https://github.com/repositories/new
◆GitHubデプロイ
git remote add origin git@github.com:shu0115/rails4sample01.git
git remote -v
-----
heroku git@heroku.com:rails4sample01.git (fetch)
heroku git@heroku.com:rails4sample01.git (push)
origin git@github.com:shu0115/rails4sample01.git (fetch)
origin git@github.com:shu0115/rails4sample01.git (push)
-----
git push -u origin master
-----
Counting objects: 100, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (87/87), done.
Writing objects: 100% (100/100), 101.17 KiB, done.
Total 100 (delta 6), reused 0 (delta 0)
To git@github.com:shu0115/rails4sample01.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
-----
◆GitHubリポジトリページ
https://github.com/shu0115/rails4sample01