● Sqlite3へ、.csv /.txtファイルからデータをインポート
まずはSqlite3のドキュメントを見ると、インポートの方法として ".import Data_FILE DB_TABLE" とある
また、ネット上の情報では以下のように示されていて、この方法でうまくいった
$ sqlite3 -separator , /home/hito/photos/db/development.sqlite3 ".import /home/hito/dbtest.txt photos"
データベースが "development.sqlite3"、テーブル名は "photos"、インポートするデータのファイルが "dbtest.txt"である
"dbtest.txt" の拡張子は ".csv" でも可。 また、ファイル内の記述として、文字列の括りに使われる ダブル・クォーテーションは消しておく。 今回は不具合がなかったが、文字コードと改行も影響すると思われる。 ちなみに "dbtest.txt" は UTF-8、Linux標準の改行コード
実行結果は、
Error: /home/hito/dbtest2.txt line 1: expected 20 columns of data but found 17
と表示された。 エラー・メッセージは、「20コラムあるべきところ、見つかったのは17項」との事。 Scaffoldで打ち込んだ内容を確認したが、作成されたテーブルはやはり17項目で合っている
テーブルの構造を確認するために、Firefoxに "Sqlite Manager" というアドオンを入れ、Railsで作成されたSqlite3のデータベースを参照するよう、 "/home/hito/photos/db/development.sqlite3" を指定した。 すると、Scaffoldで指定したコラム以外に、頭に "ID" というデータ・ベースの "キー" に当たるコラムが、末尾には "Created" と "Updated" という2つの日付のコラムが追加されていた (Railsの仕様との事) ので、これに対応するコラムを "dbtest.txt" に追記した。 ちなみに日付は "2011/10/22" という形式で対応できた
再度トライ。
$ sqlite3 -separator , /home/hito/photos/db/development.sqlite3 ".import /home/hito/dbtest3.csv photos"
$
エラーは表示されず、間もなくプロンプトが現れた
Firefoxで確認したところ、無事にデータがインポートされていた
ページ
2011年10月22日土曜日
2011年9月30日金曜日
Ruby on Rails (Rails3)をインストール (ubuntu10.04JP)
(2011.06.19の記事に追記)
● 'rails server' を実行する時点で以下のようなエラーが発生
● 環境は: ruby 1.9.2-p290 rvm 1.8.5 gem 1.8.10 rails 3.1.0
● 対処
'rails new ...' で作成されたディレクトリに入り、 'Gemfile' を開いて次の1行を加筆する
gem 'therubyracer'
$ bundle install
● 結果
無事にサーバーが起動
$ rails s
=> Booting WEBrick
=> Rails 3.1.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-09-30 16:42:03] INFO WEBrick 1.3.1
[2011-09-30 16:42:03] INFO ruby 1.9.2 (2011-07-09) [x86_64-linux]
Gemfileの編集の前に 'gem install execjs' を実行してみたが、エラー結果には変化なかった。 ちなみに 'therubyracer' というのは、'Google V8 embedded within Ruby' な ExecJsがサポートするRuntime。 他にも https://github.com/sstephenson/execjs に同様なRuntimeがリストアップされている
● 'rails server' を実行する時点で以下のようなエラーが発生
$ rails s
/home/tj/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.2.9/lib/execjs/runtimes.rb:47:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
● 環境は: ruby 1.9.2-p290 rvm 1.8.5 gem 1.8.10 rails 3.1.0
● 対処
'rails new ...' で作成されたディレクトリに入り、 'Gemfile' を開いて次の1行を加筆する
gem 'therubyracer'
$ bundle install
● 結果
無事にサーバーが起動
$ rails s
=> Booting WEBrick
=> Rails 3.1.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-09-30 16:42:03] INFO WEBrick 1.3.1
[2011-09-30 16:42:03] INFO ruby 1.9.2 (2011-07-09) [x86_64-linux]
2011年8月24日水曜日
Rails アプリケーション作成 ~続き (Rails3 on Ubuntu10.04LTS)
○ 以前の記事(2011.03.19、 2011.06.19) の続き 〜 on Ubuntu 10.04 LTS
● Ruby, Railsをインストール
以前の記事の手順通りに再度インストールから始め、サーバーの起動を確認するところまで出来た
rvmのインストールで、'rvm notes'を実行すると以下のような表示が。そして気になるのが下線の部分
$ rvm notes
Notes for Linux ( DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.04
DISTRIB_CODENAME=lucid
DISTRIB_DESCRIPTION="Ubuntu 10.04.2 LTS" )
NOTE: 'ruby' represents Matz's Ruby Interpreter (MRI) (1.8.X, 1.9.X)
This is the *original* / standard Ruby Language Interpreter
'ree' represents Ruby Enterprise Edition
'rbx' represents Rubinius
bash >= 3.2 is required
curl is required
git is required (>= 1.7 recommended)
patch is required (for ree and some ruby-head's).
If you wish to install rbx and/or Ruby 1.9 head (MRI) (eg. 1.9.2-head),
then you must install and use rvm 1.8.7 first.
If you wish to have the 'pretty colors' again,
set 'export rvm_pretty_print_flag=1' in ~/.rvmrc.
dependencies:
# For RVM
rvm: bash curl git
# For Ruby (MRI, Rubinius, & REE) you should install the following OS dependencies:
ruby: /usr/bin/apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake
# For JRuby (if you wish to use it) you will need:
jruby: /usr/bin/apt-get install curl g++ openjdk-6-jre-headless
jruby-head: /usr/bin/apt-get install ant openjdk-6-jdk
# In addition to ruby: dependencies,
ruby-head: subversion
# For IronRuby (if you wish to use it) you will need:
ironruby: /usr/bin/apt-get install curl mono-2.0-devel
For rbx (Rubinius) more than 600MB of free RAM required.
NOTE: For all installations, as of 1.7, RVM no longer autoloads .rvmrc files. In order to return this functionality, you MUST add 'export rvm_project_rvmrc=1' to your $HOME/.rvmrc file.
This causes RVM to override 'cd' which, while toggleable even < 1.7, is currently defaulted to 'off'. This knob returns the previous behaviour to active which causes per-project .rvmrc files to be loaded once again.
Example: echo 'export rvm_project_rvmrc=1' >> $HOME/.rvmrc && rvm reload
● 各バージョンを確認してみる
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
$ rails -v
Rails 3.0.10
$ gem -v
1.3.7
$ sqlite3 -version
3.6.22
● Migrate ~DBテーブルの作成
Rails2と同様、$HOME/User/photos/db/migrate に'201108xxxxxxxx_create_photos.rb'といった、DBのフィールドを作成用する要素が生成されている。ファイルの中身が以下
class CreatePhotos < ActiveRecord::Migration
def self.up
create_table :photos do |t|
t.integer :key
t.text :alb_tt
t.text :place
t.text :content
t.integer :year1
t.string :year2
t.integer :month
t.integer :day
t.text :filename
t.text :image
t.string :cd_no
t.string :dvd_no
t.string :region
t.text :remark
t.text :people
t.timestamps
end
end
$ rake db:migrate
この状態で、レコードの新規作成、編集、一覧表示、削除が出来ることを確認 -> Ok
つづく
*参照: WEB+DB Press誌 Vol.58 'Rails3'、O'Reilly 'Head First Rails'
● Ruby, Railsをインストール
以前の記事の手順通りに再度インストールから始め、サーバーの起動を確認するところまで出来た
rvmのインストールで、'rvm notes'を実行すると以下のような表示が。そして気になるのが下線の部分
$ rvm notes
Notes for Linux ( DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.04
DISTRIB_CODENAME=lucid
DISTRIB_DESCRIPTION="Ubuntu 10.04.2 LTS" )
NOTE: 'ruby' represents Matz's Ruby Interpreter (MRI) (1.8.X, 1.9.X)
This is the *original* / standard Ruby Language Interpreter
'ree' represents Ruby Enterprise Edition
'rbx' represents Rubinius
bash >= 3.2 is required
curl is required
git is required (>= 1.7 recommended)
patch is required (for ree and some ruby-head's).
If you wish to install rbx and/or Ruby 1.9 head (MRI) (eg. 1.9.2-head),
then you must install and use rvm 1.8.7 first.
If you wish to have the 'pretty colors' again,
set 'export rvm_pretty_print_flag=1' in ~/.rvmrc.
dependencies:
# For RVM
rvm: bash curl git
# For Ruby (MRI, Rubinius, & REE) you should install the following OS dependencies:
ruby: /usr/bin/apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake
# For JRuby (if you wish to use it) you will need:
jruby: /usr/bin/apt-get install curl g++ openjdk-6-jre-headless
jruby-head: /usr/bin/apt-get install ant openjdk-6-jdk
# In addition to ruby: dependencies,
ruby-head: subversion
# For IronRuby (if you wish to use it) you will need:
ironruby: /usr/bin/apt-get install curl mono-2.0-devel
For rbx (Rubinius) more than 600MB of free RAM required.
NOTE: For all installations, as of 1.7, RVM no longer autoloads .rvmrc files. In order to return this functionality, you MUST add 'export rvm_project_rvmrc=1' to your $HOME/.rvmrc file.
This causes RVM to override 'cd' which, while toggleable even < 1.7, is currently defaulted to 'off'. This knob returns the previous behaviour to active which causes per-project .rvmrc files to be loaded once again.
Example: echo 'export rvm_project_rvmrc=1' >> $HOME/.rvmrc && rvm reload
● 各バージョンを確認してみる
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
$ rails -v
Rails 3.0.10
$ gem -v
1.3.7
$ sqlite3 -version
3.6.22
$ rvm -v
rvm 1.7.2
● Railsアプリケーション作成開始
$ rails new /home/hito/photos
● Scaffold (データベース内のデータの登録、読込み、更新、削除のためのコードを生成する)
$ cd photos
$ rails g scaffold photo key:integer alb_tt:text place:text content:text year1:integer year2:string month:integer day:integer filename:text image:text cd_no:string dvd_no:string region:string remark:text people:text
invoke active_record
create db/migrate/20110821111257_create_photos.rb
create app/models/photo.rb
invoke test_unit
create test/unit/photo_test.rb
create test/fixtures/photos.yml
route resources :photos
invoke scaffold_controller
create app/controllers/photos_controller.rb
invoke erb
create app/views/photos
create app/views/photos/index.html.erb
create app/views/photos/edit.html.erb
create app/views/photos/show.html.erb
create app/views/photos/new.html.erb
create app/views/photos/_form.html.erb
invoke test_unit
create test/functional/photos_controller_test.rb
invoke helper
create app/helpers/photos_helper.rb
invoke test_unit
create test/unit/helpers/photos_helper_test.rb
invoke stylesheets
create public/stylesheets/scaffold.css
● ブラウザでアクセスしてみる
127.0.0.1:3000/photos
● Migrate ~DBテーブルの作成
Rails2と同様、$HOME/User/photos/db/migrate に'201108xxxxxxxx_create_photos.rb'といった、DBのフィールドを作成用する要素が生成されている。ファイルの中身が以下
class CreatePhotos < ActiveRecord::Migration
def self.up
create_table :photos do |t|
t.integer :key
t.text :alb_tt
t.text :place
t.text :content
t.integer :year1
t.string :year2
t.integer :month
t.integer :day
t.text :filename
t.text :image
t.string :cd_no
t.string :dvd_no
t.string :region
t.text :remark
t.text :people
t.timestamps
end
end
Rakeにてデータベースを作成する。以下のコマンドによって、SQLではCREATE TABLEが実行される
$ rake db:migrate
== CreatePhotos: migrating ===================================================
-- create_table(:photos)
-> 0.0224s
== CreatePhotos: migrated (0.0233s) ==========================================
● アプリケーション・ユニットの各種テスト
$ rake
Loaded suite /home/hito/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/rake_test_loader
Started
.
Finished in 0.184379 seconds.
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 33681
Loaded suite /home/hito/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/rake_test_loader
Started
.......
Finished in 0.755171 seconds.
7 tests, 10 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 56047
● ブラウザに表示する ~コンソールの表示とブラウザの表示
$ rails s
=> Booting WEBrick
=> Rails 3.0.10 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-08-21 20:56:15] INFO WEBrick 1.3.1
[2011-08-21 20:56:15] INFO ruby 1.9.2 (2011-07-09) [x86_64-linux]
[2011-08-21 20:56:15] INFO WEBrick::HTTPServer#start: pid=1734 port=3000
DEPRECATION WARNING: config.action_view.debug_rjs will be removed in 3.1, from 3.1 onwards you will need to install prototype-rails to continue to use RJS templates . (called from service at /home/hito/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111)
Started GET "/photos" for 127.0.0.1 at 2011-08-21 20:56:19 +0900
Processing by PhotosController#index as HTML
Photo Load (3.7ms) SELECT "photos".* FROM "photos"
Rendered photos/index.html.erb within layouts/application (11.6ms)
Completed 200 OK in 149ms (Views: 17.8ms | ActiveRecord: 3.7ms)
この状態で、レコードの新規作成、編集、一覧表示、削除が出来ることを確認 -> Ok
つづく
*参照: WEB+DB Press誌 Vol.58 'Rails3'、O'Reilly 'Head First Rails'
2011年6月19日日曜日
Ruby on Rails (Rails3)をインストール (ubuntu11.04JP)
● まず
参考にしたサイトは: ubuntuのCommunity Documentations、rvmのInstall の2つ
この投稿の下の方にあれこれ試行錯誤した経過を残しておきます。今回は Leex40さんに
いろいろ教えて頂きました。なかでも参考にするドキュメント類で、例えば上記の2つ。
まずは「おおもと」をあたる。これが近道... というより定石なんでしょうね。他RailsForum
● Sqlite3をインストール
● Ruby1.9.2をインストール (1.9.1からGemが同梱されています)
● rvmをインストール (Ruby Version Manager)
$ sudo apt-get install git-core (必要です)
$ sudo apt-get install curl (必要です)
$ cd
$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
スペースも含めこの通りに打ち込むとOk。 .bashrc に以下が追記される
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
$ source .bashrc
$ rvm reload
$ rvm -v (確認) -> rvm 1.6.20 by Wayne E. Seguin
$ rvm notes -> 注意書きと、環境に応じて更にインストールの必要なものが表示される
# For Ruby (MRI & ree) you should install the following OS dependencies:
ruby: /usr/bin/apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev
また、.bashrcの '&& return' とある行を書き換えるよう書かれている。書き換えで行の先頭が'if'であれば対応する'fi'を入れる... なども記載あり
$ sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev
● Railsをインストール
$ gem install rails --no-ri --no-rdoc
● 実行してみる
$ rails new /home/hito/sample -> Ok
$ cd /home/hito/sample
$ rails server -> う゛ エラー
Could not find gem 'sqlite3 (>= 0)' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.
$ bundle install -> なんとSQLite3が入ってなかったみたい... 先のlibは必要です
Installing sqlite3 (1.3.3) with native extensions
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
$ rails server
=> Booting WEBrick
=> Rails 3.0.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-06-19 15:54:02] INFO WEBrick 1.3.1
[2011-06-19 15:54:02] INFO ruby 1.9.2 (2011-02-18) [i686-linux]
[2011-06-19 15:54:02] INFO WEBrick::HTTPServer#start: pid=27849 port=3000
ブラウザで'127.0.0.1:3000'を打つと... きました 'Welcome aboard'
● Railsの本
- - - - - - これ以下はちょっと前に苦戦した跡です - - - - - - -
● まず
$ sudo apt-get install build-essential libssl-dev libreadline5-dev zlib1g-dev
● Sqlite3をインストール
$ sudo apt-get install sqlite3 libsqlite3-ruby
試しに:
$ sqlite3
SQLite3 version 3.6.22
sqlite >
動きました。 参考にしたウェブサイト: UbuntuにSQLite3をインストールして使ってみた
sqlite > .quit で抜ける
● Ruby1.8.7をインストール
Rubyサイトからダウンロード
$ tar xzvf ruby-1.8.7-p334.tar.gz
$ cd ruby-1.8.7-p334
$ ./configure
$ make
$ make install
● Gemをインストール
RubyForgeからrubygems-1.6.2をダウンロード
$ tar xzvf rubygems-1.6.2.tgz
$ cd rubygems-1.6.2.tgz
$ sudo ruby setup.rb
$ export PATH=$PATH:~/.gem/ruby/1.8/bin
$ source ~/.profile
● rvm(Ruby Version Manager)をインストール
rvmについて、ウェブサイト: Leex40、のどをRubyでいっぱいにしてを参考にしました
$ sudo gem install rvm (rvm-1.6.20がインストールされた)
$ rvm-install ...これが動かない...
● Railsをインストール
$ sudo gem install rails
Railsはrails-3.0.9がインストールされた
● 実行してみる
$ rails new /home/xxx/photos
photosというディレクトリが作成され、そこに必要なものが生成されていた。見た目にはOk。
$ rails server
動作せず。エラーメッセージは:
Could not find gem 'sqlite3 (>= 0)' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.
● Rails3を使う記事など
ウェブサイト: Ruby on Rails3をはじめよう、ubuntuとRails3、ubuntuにRuby1.9.2とRails3をインストールした、悪あがきプログラマー
参考にしたサイトは: ubuntuのCommunity Documentations、rvmのInstall の2つ
この投稿の下の方にあれこれ試行錯誤した経過を残しておきます。今回は Leex40さんに
いろいろ教えて頂きました。なかでも参考にするドキュメント類で、例えば上記の2つ。
まずは「おおもと」をあたる。これが近道... というより定石なんでしょうね。他RailsForum
● さて
$ sudo apt-get install build-essential
● Sqlite3をインストール
$ sudo apt-get install sqlite3 libsqlite3-dev
試しに:
$ sqlite3
SQLite3 version 3.7.4
sqlite >
動きました。 参考にしたウェブサイト: UbuntuにSQLite3をインストールして使ってみた
sqlite > .quit で抜ける
● Ruby1.9.2をインストール (1.9.1からGemが同梱されています)
Rubyサイトからダウンロード
$ tar xzvf ruby-1.9.2-p180.tar.gz
$ cd ruby-1.9.2-p180
$ ./configure
$ make
$ sudo make install
● rvmをインストール (Ruby Version Manager)
$ sudo apt-get install git-core (必要です)
$ sudo apt-get install curl (必要です)
$ cd
$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
スペースも含めこの通りに打ち込むとOk。 .bashrc に以下が追記される
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
$ source .bashrc
$ rvm reload
$ rvm -v (確認) -> rvm 1.6.20 by Wayne E. Seguin
$ rvm notes -> 注意書きと、環境に応じて更にインストールの必要なものが表示される
# For Ruby (MRI & ree) you should install the following OS dependencies:
ruby: /usr/bin/apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev
また、.bashrcの '&& return' とある行を書き換えるよう書かれている。書き換えで行の先頭が'if'であれば対応する'fi'を入れる... なども記載あり
$ sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev
$ rvm install 1.9.2 -> Ruby1.9.2と関連するものをユーザー・ディレクトリにインストールする
$ rvm use 1.9.2 -> Ruby1.9.2を使うように設定される。但しシェル実行の度に打つ必要あり
$ rvm use 1.9.2 --default -> と指定すると常に1.9.2を参照するようになる
Using /home/hito/.rvm/gems/ruby-1.9.2-p180
$ rvm use system -> でrvmに依存せずにインストールされたRubyを参照するようになる
● Railsをインストール
$ gem install rails --no-ri --no-rdoc
● 実行してみる
$ rails new /home/hito/sample -> Ok
$ cd /home/hito/sample
$ rails server -> う゛ エラー
Could not find gem 'sqlite3 (>= 0)' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.
$ bundle install -> なんとSQLite3が入ってなかったみたい... 先のlibは必要です
Installing sqlite3 (1.3.3) with native extensions
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
$ rails server
=> Booting WEBrick
=> Rails 3.0.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-06-19 15:54:02] INFO WEBrick 1.3.1
[2011-06-19 15:54:02] INFO ruby 1.9.2 (2011-02-18) [i686-linux]
[2011-06-19 15:54:02] INFO WEBrick::HTTPServer#start: pid=27849 port=3000
ブラウザで'127.0.0.1:3000'を打つと... きました 'Welcome aboard'
● Railsの本
- - - - - - これ以下はちょっと前に苦戦した跡です - - - - - - -
● まず
$ sudo apt-get install build-essential libssl-dev libreadline5-dev zlib1g-dev
● Sqlite3をインストール
$ sudo apt-get install sqlite3 libsqlite3-ruby
試しに:
$ sqlite3
SQLite3 version 3.6.22
sqlite >
動きました。 参考にしたウェブサイト: UbuntuにSQLite3をインストールして使ってみた
sqlite > .quit で抜ける
● Ruby1.8.7をインストール
Rubyサイトからダウンロード
$ tar xzvf ruby-1.8.7-p334.tar.gz
$ cd ruby-1.8.7-p334
$ ./configure
$ make
$ make install
● Gemをインストール
RubyForgeからrubygems-1.6.2をダウンロード
$ tar xzvf rubygems-1.6.2.tgz
$ cd rubygems-1.6.2.tgz
$ sudo ruby setup.rb
$ export PATH=$PATH:~/.gem/ruby/1.8/bin
$ source ~/.profile
● rvm(Ruby Version Manager)をインストール
rvmについて、ウェブサイト: Leex40、のどをRubyでいっぱいにしてを参考にしました
$ sudo gem install rvm (rvm-1.6.20がインストールされた)
$ rvm-install ...これが動かない...
● Railsをインストール
$ sudo gem install rails
Railsはrails-3.0.9がインストールされた
もし'File not found: lib' と返ってくる場合は以下のようにRailsをインストールする
$ sudo gem install rails --no-ri --no-rdoc
● 実行してみる
$ rails new /home/xxx/photos
photosというディレクトリが作成され、そこに必要なものが生成されていた。見た目にはOk。
$ rails server
動作せず。エラーメッセージは:
Could not find gem 'sqlite3 (>= 0)' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.
$ bundle install を実行するもエラーは変わらず
$ sudo apt-get install libsqlite3-dev 今回はこれでOk
$ sudo apt-get install libsqlite3-dev 今回はこれでOk
● Rails3を使う記事など
ウェブサイト: Ruby on Rails3をはじめよう、ubuntuとRails3、ubuntuにRuby1.9.2とRails3をインストールした、悪あがきプログラマー
2011年3月19日土曜日
Rails アプリケーション作成(MacOsX 10.6.6)
● 基本
MacOS 10.6.6 に含まれる Rails:
$ ruby -v → Ruby 1.8.7 (universal-darwin10.0)
$ rails -v → Rails 2.3.5
$ gem -v → Gems 1.3.5
$ sqlite3 -version → SQLite3 3.6.12
$ cd /Users/xxxxxx ( /home/xxxxxx に相当する場所)
$ rails photos ( "photos" というアプリケーションを作成。このコマンドで "photos"というディレクトリが作成され、そこに最低限必要なアプリケーションの要素が作成される)
$ cd photos
$ ruby script/server ("photos" ディレクトリに入り、ruby コマンドで Web サーバーを立ち上げる)
Macname:~ xxxxxx$ ls
Applications Downloads Music Sites
Desktop Library Pictures eclipse-workspace
Documents Movies Public photos
Macname:~ xxxxxx$ cd photos
Macname:photos xxxxxx$ ruby script/server
=> Booting Mongrel
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
$ ruby -v → Ruby 1.8.7 (universal-darwin10.0)
$ rails -v → Rails 2.3.5
$ gem -v → Gems 1.3.5
$ sqlite3 -version → SQLite3 3.6.12
$ cd /Users/xxxxxx ( /home/xxxxxx に相当する場所)
$ rails photos ( "photos" というアプリケーションを作成。このコマンドで "photos"というディレクトリが作成され、そこに最低限必要なアプリケーションの要素が作成される)
$ cd photos
$ ruby script/server ("photos" ディレクトリに入り、ruby コマンドで Web サーバーを立ち上げる)
Macname:~ xxxxxx$ ls
Applications Downloads Music Sites
Desktop Library Pictures eclipse-workspace
Documents Movies Public photos
Macname:~ xxxxxx$ cd photos
Macname:photos xxxxxx$ ruby script/server
=> Booting Mongrel
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
● ブラウザで起動を確認
アドレス: 127.0.0.1:3000
● Scaffold (フィールドの定義)
$ cd photos (上記と同じ場所)
$ ruby script/generate scaffold photo key:integer alb_tt:text place:text content:text year1:integer year2:string month:integer day:integer filename:text image:text cd_no:string dvd_no:string region:string remark:text people:text
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/photos
exists app/views/layouts/
exists test/functional/
exists test/unit/
create test/unit/helpers/
exists public/stylesheets/
create app/views/photos/index.html.erb
create app/views/photos/show.html.erb
create app/views/photos/new.html.erb
create app/views/photos/edit.html.erb
create app/views/layouts/photos.html.erb
create public/stylesheets/scaffold.css
create app/controllers/photos_controller.rb
create test/functional/photos_controller_test.rb
create app/helpers/photos_helper.rb
create test/unit/helpers/photos_helper_test.rb
route map.resources :photos
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/photo.rb
create test/unit/photo_test.rb
create test/fixtures/photos.yml
create db/migrate
create db/migrate/20110324120355_create_photos.rb
Macname:photos xxxxxx$
● ブラウザで表示してみる
アドレス: 127.0.0.1:3000
● Scaffold (フィールドの定義)
$ cd photos (上記と同じ場所)
$ ruby script/generate scaffold photo key:integer alb_tt:text place:text content:text year1:integer year2:string month:integer day:integer filename:text image:text cd_no:string dvd_no:string region:string remark:text people:text
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/photos
exists app/views/layouts/
exists test/functional/
exists test/unit/
create test/unit/helpers/
exists public/stylesheets/
create app/views/photos/index.html.erb
create app/views/photos/show.html.erb
create app/views/photos/new.html.erb
create app/views/photos/edit.html.erb
create app/views/layouts/photos.html.erb
create public/stylesheets/scaffold.css
create app/controllers/photos_controller.rb
create test/functional/photos_controller_test.rb
create app/helpers/photos_helper.rb
create test/unit/helpers/photos_helper_test.rb
route map.resources :photos
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/photo.rb
create test/unit/photo_test.rb
create test/fixtures/photos.yml
create db/migrate
create db/migrate/20110324120355_create_photos.rb
Macname:photos xxxxxx$
● ブラウザで表示してみる
● データベース作成のステップ
/Users/xxxxxx/photos/db/migrate/ に "20110324120355_create_photos.rb" が作成され、これを元にデータベースのテーブルが作成される
登録:
投稿 (Atom)




