引き続き ruby のおさらいをしています。
"Head First Rails":http://www.oreilly.co.jp/books/9784873114385/ というPDFを買いました。
読み進めるうちに環境が本と今のものとで少し違うので、簡単に読み進めるために当時の環境ぽいもの(rails 2.x)を作りました。
ざっくりいうと、rubyinstaller 1.8.7 + devkit tdm-32 + msysgit に
gem install rails -v 2.2.2 したものです。
動くもんなんですね。
新しいのはググるとたくさんあったので、必要な方がもし居たら :)
こちら、とても参考になりました。ありがとうございます:
* Windows で Ruby バージョン 1.8.7 あるいは 1.9.3-p429 のインストール (RubyInstaller を使用) http://www.kkaneko.com/rinkou/ruby/rubyinstaller.html
* MinGW+MSYS と msysgit を連携させる http://www.devlog.alt-area.org/?p=2740
以下メモ:
rubyinstaller & devkit
C:\>mkdir ruby
install rubyinstaller 1.8.7 to C:\ruby\187.
unpack devkit to C:\ruby\187.
C:\ruby\187>ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [i386-mingw32]
C:\ruby\187>gem -v
1.8.24
C:\ruby\187>ruby dk.rb init
[INFO] found RubyInstaller v1.8.7 at C:/ruby/187
Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.
C:\ruby\187>notepad config.yml
C:\ruby\187>ruby dk.rb install
[INFO] Updating convenience notice gem override for 'C:/ruby/187'
[INFO] Installing 'C:/ruby/187/lib/ruby/site_ruby/devkit.rb'
gem update
open C:\ruby\187\msys.bat
$ notepad %HOMEDRIVE%%HOMEPATH%\.gemrc
install: --no-ri --no-rdoc
update: --no-ri --no-rdoc
$ gem -v
1.8.24
$ gem update
Updating installed gems
Nothing to update
git & gitk
install msysgit to C:\ruby\Git.
$ touch .profile
$ notepad .profile
exec /bin/bash
$ touch .bashrc
$ notepad .bashrc
PATH="$PATH":/c/ruby/Git/bin
source /c/ruby/Git/etc/git-prompt.sh
PS1='[\[\033[32m\]\u@\h\[\033[00m\]:\[\033[33m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]]\$ '
# => logout & login
$ git config --global core.autocrlf false
$ git config --global user.name sato1043
$ git config --global user.email sato1043@gmail.com
$ git config --global push.default simple
sqlite3
download shell and dll
mkdir C:\ruby\sqlite3
put extracted files to C:\ruby\sqlite3
add C:\sqlite3 to PATH
$ gem install sqlite3-ruby --include-dependencies
INFO: `gem install -y` is now default and will be removed
INFO: use --ignore-dependencies to install only the gems you list
Fetching: sqlite3-1.3.9-x86-mingw32.gem (100%)
Fetching: sqlite3-ruby-1.3.3.gem (100%)
#######################################################
Hello! The sqlite3-ruby gem has changed it's name to just sqlite3. Rather than
installing `sqlite3-ruby`, you should install `sqlite3`. Please update your
dependencies accordingly.
Thanks from the Ruby sqlite3 team!
<3 <3 <3 <3
#######################################################
Successfully installed sqlite3-1.3.9-x86-mingw32
Successfully installed sqlite3-ruby-1.3.3
2 gems installed
postgresql
http://www.enterprisedb.com/products-services-training/products/postgresql-overview
windows installer (9.3)
add C:\ruby\psql\bin to PATH
$ gem install pg
Fetching: pg-0.17.1-x86-mingw32.gem (100%)
Successfully installed pg-0.17.1-x86-mingw32
1 gem installed
rails 2.2.2
$ gem install pkg-config
Fetching: pkg-config-1.1.5.gem (100%)
Successfully installed pkg-config-1.1.5
1 gem installed
$ gem install rails -v 2.2.2
Fetching: rake-10.3.2.gem (100%)
Fetching: activesupport-2.2.2.gem (100%)
Fetching: activerecord-2.2.2.gem (100%)
Fetching: actionpack-2.2.2.gem (100%)
Fetching: actionmailer-2.2.2.gem (100%)
Fetching: activeresource-2.2.2.gem (100%)
Fetching: rails-2.2.2.gem (100%)
Successfully installed rake-10.3.2
Successfully installed activesupport-2.2.2
Successfully installed activerecord-2.2.2
Successfully installed actionpack-2.2.2
Successfully installed actionmailer-2.2.2
Successfully installed activeresource-2.2.2
Successfully installed rails-2.2.2
7 gems installed
$ rails tickets
create
create app/controllers
create app/helpers
:
$ ruby script/server
=> Booting WEBrick...
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from C:/ruby/187/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/rails/gem_dependency.rb:21.
:
:
NOTE: Gem::SourceIndex#initialize is deprecated with no replacement. It will be removed on or after 2011-11-01.
Gem::SourceIndex#initialize called from C:/ruby/187/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/rails/vendor_gem_source_ind
ex.rb:100.
=> Rails 2.2.2 application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2014-06-26 18:12:55] INFO WEBrick 1.3.1
[2014-06-26 18:12:55] INFO ruby 1.8.7 (2013-06-27) [i386-mingw32]
[2014-06-26 18:12:55] INFO WEBrick::HTTPServer#start: pid=3212 port=3000
# => here, Ctrl+C
$ gem -v
1.8.24
$ gem update --system 1.6.2
Updating rubygems-update
Fetching: rubygems-update-1.6.2.gem (100%)
Successfully installed rubygems-update-1.6.2
Installing RubyGems 1.6.2
RubyGems 1.6.2 installed
・ソ=== 1.6.2 / 2011-03-08
Bug Fixes:
* require of an activated gem could cause activation conflicts. Fixes
Bug #29056 by Dave Verwer.
* `gem outdated` now works with up-to-date prerelease gems.
------------------------------------------------------------------------------
RubyGems installed the following executables:
C:/ruby/187/bin/gem
RubyGems system software updated
$ ruby script/server
=> Booting WEBrick...
=> Rails 2.2.2 application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2014-06-26 18:20:04] INFO WEBrick 1.3.1
[2014-06-26 18:20:04] INFO ruby 1.8.7 (2013-06-27) [i386-mingw32]
[2014-06-26 18:20:04] INFO WEBrick::HTTPServer#start: pid=4976 port=3000
# => here, open browser and enter URL http://localhost:3000/
127.0.0.1 - - [26/Jun/2014:18:20:30 東京 (標準時)] "GET / HTTP/1.1" 200 7385
- -> /
127.0.0.1 - - [26/Jun/2014:18:20:31 東京 (標準時)] "GET /javascripts/effects.js HTTP/1.1" 200 38675
http://localhost:3000/ -> /javascripts/effects.js
127.0.0.1 - - [26/Jun/2014:18:20:31 東京 (標準時)] "GET /javascripts/prototype.js HTTP/1.1" 200 129738
http://localhost:3000/ -> /javascripts/prototype.js
127.0.0.1 - - [26/Jun/2014:18:20:31 東京 (標準時)] "GET /images/rails.png HTTP/1.1" 200 6646
http://localhost:3000/ -> /images/rails.png
127.0.0.1 - - [26/Jun/2014:18:20:32 東京 (標準時)] "GET /favicon.ico HTTP/1.1" 200 0
- -> /favicon.ico
in the end:
$ gem list
*** LOCAL GEMS ***
actionmailer (2.2.2)
actionpack (2.2.2)
activerecord (2.2.2)
activeresource (2.2.2)
activesupport (2.2.2)
diff-lcs (1.2.5)
git (1.2.7)
pg (0.17.1 x86-mingw32)
pkg-config (1.1.5)
rails (2.2.2)
rake (10.3.2)
rspec (3.0.0)
rspec-core (3.0.2)
rspec-expectations (3.0.2)
rspec-mocks (3.0.2)
rspec-support (3.0.2)
rubygems-update (1.7.1, 1.6.2)
sqlite3 (1.3.9 x86-mingw32)
sqlite3-ruby (1.3.3)
はてさて、ここからごにょごにょします。
#rubyinstallerのdevkitのmsysにvimを入れてないな。。。
P.S.
rake db:migrate
$ rake db:migrate
rake aborted!
ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc 2.4.2+) instead.
(See full trace by running task with --trace)
$ gem list |grep rake
rake (10.3.2)
$ gem uninstall rake -v 10.3.2
You have requested to uninstall the gem:
rake-10.3.2
git-1.2.7 depends on [rake (>= 0)]
diff-lcs-1.2.5 depends on [rake (~> 10.0)]
pkg-config-1.1.5 depends on [rake (>= 0)]
rails-2.2.2 depends on [rake (>= 0.8.3)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn] Y
Remove executables:
rake
in addition to the gem? [Yn] Y
Removing rake
Successfully uninstalled rake-10.3.2
$ gem install rake -v 0.8.7
Fetching: rake-0.8.7.gem (100%)
Successfully installed rake-0.8.7
1 gem installed
$ gem list |grep rake
rake (0.8.7)
$ rake db:migrate
(in C:/ruby/187/home/sato1_000/projects/tickets)
== CreateTickets: migrating ==================================================
-- create_table(:tickets)
-> 0.0154s
== CreateTickets: migrated (0.0164s) =========================================
P.S. 140627 Postgresqlと連携できました。動きます。やっぱりRailsはできる子ですね。
(open msys.bat)
$ rails tickets -d postgresql
create
create app/controllers
create app/helpers
:
:
$ createuser -U postgres -P tickets
新しいロールのパスワード:
もう一度入力してください:
新しいロールをスーパーユーザとしますか? (y/n)n
新しいロールにデータベース作成権限を与えますか? (y/n)y
新しいロールにロールを作成する権限を与えますか? (y/n)n
パスワード:
$ notepad database.yml
:
development:
adapter: postgresql
encoding: utf8
database: tickets_development
pool: 5
username: tickets
password: 9T!TPtBm0zOA
host: localhost
port: 5432
:
![WS000000.JPG](https://qiita-image-store.s3.amazonaws.com/0/43278/207bbd71-e3a5-1c96-6df3-0a778e5d41d7.jpeg)
![WS000001.JPG](https://qiita-image-store.s3.amazonaws.com/0/43278/98940d90-80b7-f73c-d807-95de24446b2e.jpeg)
$ gem install sql
Fetching: sql-0.0.1.gem (100%)
Successfully installed sql-0.0.1
1 gem installed
$ rake db:create RAILS_ENV=development
(in C:/ruby/187/home/sato1043/projects/tickets)
$ ruby script/generate scaffold ticket name:string seat_id_seq:string address:text price_paid:decimal email_address:string
C:/ruby/187/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/rails_generator/lookup.rb:212:Warning: Gem::cache is deprecated and
will be removed on or after August 2011. Use Gem::source_index.
C:/ruby/187/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/rails_generator/lookup.rb:234:Warning: Gem::cache is deprecated and
will be removed on or after August 2011. Use Gem::source_index.
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/tickets
:
(http://archives.ryandaigle.com/articles/2006/12/4/how-to-turn-deprecation-warnings-off-in-rails)
$ rake db:migrate
(in C:/ruby/187/home/sato1043/projects/tickets)
== CreateTickets: migrating ==================================================
-- create_table(:tickets)
-> 0.4328s
== CreateTickets: migrated (0.4348s) =========================================
$ ruby script/server
=> Booting WEBrick...
=> Rails 2.2.2 application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2014-06-27 18:53:27] INFO WEBrick 1.3.1
[2014-06-27 18:53:27] INFO ruby 1.8.7 (2013-06-27) [i386-mingw32]
[2014-06-27 18:53:27] INFO WEBrick::HTTPServer#start: pid=5220 port=3000
127.0.0.1 - - [27/Jun/2014:18:53:37 東京 (標準時)] "GET /rails/info/properties HTTP/1.1" 200 1009
http://127.0.0.1:3000/ -> /rails/info/properties
127.0.0.1 - - [27/Jun/2014:18:53:47 東京 (標準時)] "GET /tickets/ HTTP/1.1" 200 697
- -> /tickets/
127.0.0.1 - - [27/Jun/2014:18:53:48 東京 (標準時)] "GET /stylesheets/scaffold.css?1403862409 HTTP/1.1" 200 889
http://127.0.0.1:3000/tickets/ -> /stylesheets/scaffold.css?1403862409
127.0.0.1 - - [27/Jun/2014:18:53:51 東京 (標準時)] "GET /tickets/new HTTP/1.1" 200 1614
http://127.0.0.1:3000/tickets/ -> /tickets/new
http://127.0.0.1:3000/tickets/new -> /tickets/1
:
(CRUD動きました)
:
END