2010年10月25日月曜日

Rails奮闘記 サーバ立ち上げまで

だいぶ期間が空いてしまったけど…早速使ってみる。
小遣い管理システム作るぞー。
(railsのmanページに乗ってたURL:http://guides.rubyonrails.org/getting_started.htmlを参照した)

まず、ブログ領域を作成。

$ rails new testmoney
create
create README
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/views/layouts/application.html.erb
create app/mailers
create app/models
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/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 log
create log/server.log
create log/production.log
create log/development.log
create log/test.log
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 public/images
create public/images/rails.png
create public/stylesheets
create public/stylesheets/.gitkeep
create public/javascripts
create public/javascripts/application.js
create public/javascripts/controls.js
create public/javascripts/dragdrop.js
create public/javascripts/effects.js
create public/javascripts/prototype.js
create public/javascripts/rails.js
create script
create script/rails
create test
create test/performance/browsing_test.rb
create test/test_helper.rb
create test/fixtures
create test/functional
create test/integration
create test/unit
create tmp
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create vendor/plugins
create vendor/plugins/.gitkeep
次はbundler(Gem 管理ツール)のセットアップ。

$ bundle install
Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.1)
Using builder (2.1.2)
Using i18n (0.4.1)
Using activemodel (3.0.1)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.6)
Using tzinfo (0.3.23)
Using actionpack (3.0.1)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.8)
Using mail (2.2.7)
Using actionmailer (3.0.1)
Using arel (1.0.1)
Using activerecord (3.0.1)
Using activeresource (3.0.1)
Using bundler (1.0.3)
Using thor (0.14.3)
Using railties (3.0.1)
Using rails (3.0.1)
Using sqlite3-ruby (1.3.1)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
次にrakeコマンドで、データベースを作成。
$ rake db:create [~/testmoney]
(in /Users/***/testmoney)
/Library/Ruby/Gems/1.8/gems/bundler-1.0.3/lib/bundler/runtime.rb:132: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777

これで準備完了!(さすがrails!!)
サーバを起動してみる。

$ rails server
/Library/Ruby/Gems/1.8/gems/railties-3.0.1/lib/rails/script_rails_loader.rb:11: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
/Library/Ruby/Gems/1.8/gems/bundler-1.0.3/lib/bundler/runtime.rb:132: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
=> Booting WEBrick
=> Rails 3.0.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2010-10-26 00:37:45] INFO WEBrick 1.3.1
[2010-10-26 00:37:45] INFO ruby 1.8.7 (2009-06-12) [universal-darwin10.0]
[2010-10-26 00:37:45] INFO WEBrick::HTTPServer#start: pid=4063 port=3000
無事にサーバが見れてよかったです。



次回は、いよいよチューニング!
# ここまでは、マニュアル通りだもんね…。

2010年10月11日月曜日

MacPortsも入れた

Rubyのインストールが怪しいと踏んで、MacPortsもインストールした。
まとめるほどではないけど、一応メモ。
  1. 本家からイメージをダウンロード。(Installing Macportsから一つめの箇条書きにあるOS名を選択)
  2. 展開してインストール。
これだけで、OK。
使う感じは、以下のとおり。

$ port MacPorts 1.9.1
Entering interactive mode... ("help" for help, "quit" to quit)
[Users/****] > help
port
[-bcdfknopqRstuvy] [-D portdir] [-F cmdfile] action [privopts] [actionflags]
[[portname|pseudo-portname|port-url] [@version] [+-variant]... [option=value]...]...
Supported actions
------------------
activate, archive, archivefetch, build, cat, cd, checksum, clean, configure,
contents, deactivate, dependents, deps, destroot, dir, distcheck, distfiles,
dmg, dpkg, echo, ed, edit, exit, extract, fetch, file, gohome, help,
info, install, installed, lint, list, livecheck, load, location, log,
mdmg, mirror, mpkg, notes, outdated, patch, pkg, platform, portpkg,
provides, quit, rdependents, rdeps, rpm, search, select, selfupdate,
setrequested, srpm, submit, sync, test, trace, unarchive, uninstall,
unload, unsetrequested, upgrade, url, usage, variants, version, work
Pseudo-portnames
----------------
Pseudo-portnames are words that may be used in place of a portname, and
which expand to some set of ports. The common pseudo-portnames are:
all, current, active, inactive, installed, uninstalled, outdated, obsolete,
requested, unrequested and leaves.
These pseudo-portnames expand to the set of ports named.
Additional pseudo-portnames start with...
variants:, variant:, description:, depends:, depends_lib:, depends_run:,
depends_build:, depends_fetch:, depends_extract:, portdir:, homepage:, epoch:,
platforms:, platform:, name:, long_description:, maintainers:, maintainer:,
categories:, category:, version:, revision:, license:, depof:, rdepof:,
dependentof:, and rdependentof:.
These each select a set of ports based on a regex search of metadata
about the ports. In all such cases, a standard regex pattern following
the colon will be used to select the set of ports to which the
pseudo-portname expands.
Portnames that contain standard glob characters will be expanded to the
set of ports matching the glob pattern.
Port expressions
----------------
Portnames, port glob patterns, and pseudo-portnames may be logically
combined using expressions consisting of and, or, not, !, (, and ).
For more information
--------------------
See man pages: port(1), macports.conf(5), portfile(7), portgroup(7),
porthier(7), portstyle(7). Also, see http://www.macports.org.
んで、実際にRubyのインストールもしてみた。
待ち時間が長いよー…。

Railsに再挑戦(立ち上がり編)

仕事の関係でRubyに触れる機会が増えた。
しばらく使う羽目になりそうだったので、学生の頃に生半可に教わったRailsに再挑戦しようと思う。

Ruby on Railsとは(勉強的な意味で)


Railsは、一言で言えばWebアプリケーションのフレームワーク、だと考えている。(Wikipediaにまんま書いてあったw)
MVC(Model-View-Controller)アーキテクチャの考えを軸として設計されている。それぞれ、意味は以下のとおり。
  • データや手続きを表現する要素
  • モデルのデータを取り出し、ユーザに最適な形で表現する要素
  • ユーザの入力に対して応答(処理)する要素

…調べだしたら色々書きたくなったけど、まとめるのが大変そうだから、勉強系は次回に持ち越しw
今日はインストールとセットアップまで!

Railsのインストール


まずはインストールとセットアップなんだけど、Snow LeopardにはRailsがインストール済みな状態みたい。
$ rails -v
Rails 2.3.5
念のため、Railsのアップデート。
(root権限で実行するように。ここだけに限らないけど。)
と、早速エラーがw
$ sudo gem update rails
Password:
Updating installed gems
Updating rails
Successfully installed rack-1.2.1
Successfully installed rack-test-0.5.6
Successfully installed rack-mount-0.6.13
Successfully installed tzinfo-0.3.23
Successfully installed abstract-1.0.0
Successfully installed erubis-2.6.6
Successfully installed actionpack-3.0.0
Successfully installed arel-1.0.1
Successfully installed activerecord-3.0.0
Successfully installed activeresource-3.0.0
Successfully installed mime-types-1.16
Successfully installed polyglot-0.3.1
Successfully installed treetop-1.4.8
Successfully installed mail-2.2.7
Successfully installed actionmailer-3.0.0
Successfully installed rake-0.8.7
Successfully installed thor-0.14.3
Successfully installed railties-3.0.0
Successfully installed bundler-1.0.2
Successfully installed rails-3.0.0
Gems updated: rack, rack-test, rack-mount, tzinfo, abstract, erubis, actionpack, arel, activerecord, activeresource, mime-types, polyglot, treetop, mail, actionmailer, rake, thor, railties, bundler, rails
Installing ri documentation for rack-1.2.1...
Installing ri documentation for rack-test-0.5.6...
Installing ri documentation for rack-mount-0.6.13...
Installing ri documentation for tzinfo-0.3.23...
Installing ri documentation for abstract-1.0.0...
Installing ri documentation for erubis-2.6.6...
Installing ri documentation for actionpack-3.0.0...
Installing ri documentation for arel-1.0.1...
Installing ri documentation for activerecord-3.0.0...
Installing ri documentation for activeresource-3.0.0...
Installing ri documentation for mime-types-1.16...
Installing ri documentation for polyglot-0.3.1...
Installing ri documentation for treetop-1.4.8...
Installing ri documentation for mail-2.2.7...
Installing ri documentation for actionmailer-3.0.0...
Installing ri documentation for rake-0.8.7...
Installing ri documentation for thor-0.14.3...
Installing ri documentation for railties-3.0.0...
Installing ri documentation for bundler-1.0.2...
Installing ri documentation for rails-3.0.0...
File not found: lib

(途中でSuccessfully installed rails-3.0.0って出てるから、エラーじゃないのかも…)
しかし、libが無いって何だろう…?
もしかしてRailsのインストールが怪しい?と思って、再インストールをしようとしたら、
$ sudo gem install rails
Password:
Successfully installed rails-3.0.0
1 gem installed
Installing ri documentation for rails-3.0.0...
File not found: lib

同じかよ!
ちょいと調べたら、Rubyのバージョン(今が1.8.7)が最新じゃないからかも…
アップデートしてみた。
$ sudo gem update ruby
Updating installed gems
Updating libxml-ruby
Building native extensions. This could take a while...
Successfully installed libxml-ruby-1.1.4
Updating ruby-openid
Successfully installed ruby-openid-2.1.8
Updating sqlite3-ruby
Building native extensions. This could take a while...
Successfully installed sqlite3-ruby-1.3.1
Gems updated: libxml-ruby, ruby-openid, sqlite3-ruby
Installing ri documentation for libxml-ruby-1.1.4...
Enclosing class/module 'mLibXML' for module XML not known
Enclosing class/module 'mXML' for class Attr not known
Enclosing class/module 'mXML' for class AttrDecl not known
Enclosing class/module 'mXML' for class Attributes not known
Enclosing class/module 'mXML' for class Document not known
Enclosing class/module 'mXML' for class Dtd not known
Enclosing class/module 'mXML' for module Encoding not known
Enclosing class/module 'mXML' for class Error not known
Enclosing class/module 'mXML' for class HTMLParser not known
Enclosing class/module 'cXMLHtmlParser' for class Context not known
Enclosing class/module 'cXMLHtmlParser' for module Options not known
Enclosing class/module 'mXML' for class InputCallbacks not known
Enclosing class/module 'mXML' for class Namespace not known
Enclosing class/module 'mXML' for class Namespaces not known
Enclosing class/module 'mXML' for class Node not known
Enclosing class/module 'mXML' for class Parser not known
Enclosing class/module 'cXMLParser' for class Context not known
Enclosing class/module 'cXMLParser' for module Options not known
Enclosing class/module 'mXML' for class Reader not known
Enclosing class/module 'mXML' for class RelaxNG not known
Enclosing class/module 'mXML' for class SaxParser not known
Enclosing class/module 'mXML' for class Schema not known
Enclosing class/module 'mXML' for class XInclude not known
Enclosing class/module 'mXML' for module XPath not known
Enclosing class/module 'mXPath' for class Context not known
Enclosing class/module 'mXPath' for class Expression not known
Enclosing class/module 'mXPath' for class Object not known
Enclosing class/module 'mXML' for class XPointer not known
Installing ri documentation for ruby-openid-2.1.8...
Installing ri documentation for sqlite3-ruby-1.3.1...
Enclosing class/module 'mSqlite3' for class Statement not known
No definition for libversion
Installing RDoc documentation for libxml-ruby-1.1.4...
Enclosing class/module 'mLibXML' for module XML not known
Enclosing class/module 'mXML' for class Attr not known
Enclosing class/module 'mXML' for class AttrDecl not known
Enclosing class/module 'mXML' for class Attributes not known
Enclosing class/module 'mXML' for class Document not known
Enclosing class/module 'mXML' for class Dtd not known
Enclosing class/module 'mXML' for module Encoding not known
Enclosing class/module 'mXML' for class Error not known
Enclosing class/module 'mXML' for class HTMLParser not known
Enclosing class/module 'cXMLHtmlParser' for class Context not known
Enclosing class/module 'cXMLHtmlParser' for module Options not known
Enclosing class/module 'mXML' for class InputCallbacks not known
Enclosing class/module 'mXML' for class Namespace not known
Enclosing class/module 'mXML' for class Namespaces not known
Enclosing class/module 'mXML' for class Node not known
Enclosing class/module 'mXML' for class Parser not known
Enclosing class/module 'cXMLParser' for class Context not known
Enclosing class/module 'cXMLParser' for module Options not known
Enclosing class/module 'mXML' for class Reader not known
Enclosing class/module 'mXML' for class RelaxNG not known
Enclosing class/module 'mXML' for class SaxParser not known
Enclosing class/module 'mXML' for class Schema not known
Enclosing class/module 'mXML' for class XInclude not known
Enclosing class/module 'mXML' for module XPath not known
Enclosing class/module 'mXPath' for class Context not known
Enclosing class/module 'mXPath' for class Expression not known
Enclosing class/module 'mXPath' for class Object not known
Enclosing class/module 'mXML' for class XPointer not known
Installing RDoc documentation for ruby-openid-2.1.8...
Installing RDoc documentation for sqlite3-ruby-1.3.1...
Enclosing class/module 'mSqlite3' for class Statement not known
No definition for libversion

libversionが定義されてないとか、怪しいエラーっぽいけど、これでもう一回トライ。
…変わりませんでした…。明日、再調査します。
こーやってハマることが何だか懐かしいw

ちなみに、このgemsってのがよく分かってなかったので調査(メモ程度だけど)。
(RubyGemsはRubyの標準パッケージ管理システムで、Railsをはじめとした色々なパッケージの管理を行うことが可能。)

Railsのセットアップ

    じゃあ、実際にセットアップへ。

    …といきたかったけど、セットアップする前に何を作るか決めないと。
    ブログやら色々他の人がやってるけど。

    せっかくなので、最近マイブームのお小遣い帳のネタで。
    お小遣い帳管理サイトをつくろうと思います。
    次回から頑張ろう。
    (ちゃんと続けられるように…)