VirtualBoxで音が低く再生されてたのが直った。

macVirtualBoxでubuntu10.10をインストールしてたんだけど
音が低く再生される症状が起きていた。


VirtualBoxの設定で「オーディオ」 -> 「オーディオコントローラー」 を
「ICH AC97」から「SoundBlater 16」に変更して再起動したら
正常に聞こえるかな?と思ってやってみてもダメだった。


が「ICH AC97」に戻して再起動したら直った...



do_mysqlのインストールでエラー


macdm-mysql-adapterをインストールしようとしたらエラーになってしまった。

$ bundle install
Fetching source index for http://rubygems.org/
Installing addressable (2.2.2)
Installing data_objects (0.10.2)
Installing extlib (0.9.15)
Installing dm-core (1.0.2)
Installing dm-do-adapter (1.0.2)
Installing do_mysql (0.10.2) with native extensions
/Users/****/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. 
(Gem::Installer::ExtensionBuildError)

/Users/****/.rvm/rubies/ruby-1.8.7-p302/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/Users/****/.rvm/rubies/ruby-1.8.7-p302/bin/ruby
        --with-mysql-config
        --without-mysql-config
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysqlclientlib
        --without-mysqlclientlib


Gem files will remain installed in /Users/****/****/****/vendor/bundle/ruby/1.8/gems/do_mysql-0.10.2 for inspection.
Results logged to /Users/****/****/****/vendor/bundle/ruby/1.8/gems/do_mysql-0.10.2/ext/do_mysql/gem_make.out


下記のサイトを参考にエラーになったdo_mysqlをインストール

env GEM_HOME=`pwd`/vendor/bundle gem install do_mysql -- --with-mysql-dir=/usr/local/mysql/


あとは同じようにdm-mysql-adapterをインストール

env GEM_HOME=`pwd`/vendor/bundle gem install dm-mysql-adapter


これで一応インストールできたが、もう一度 bundle install をすると同じエラーになってしまう。
Gemfile.lockに追記すればエラーなくなりそうだけど、それもヤダしな。
MySQLdmgじゃなくmacportsで正しい場所(どこ?どこなの?)にインストールしないとダメっぽいなぁ。。。



追記


下記のサイトを参考にMySQLmacportsでインストールしたらエラーがなくなった!

$ bundle install
Fetching source index for http://rubygems.org/
Using addressable (2.2.2) 
Using data_objects (0.10.2) 
Using extlib (0.9.15) 
Using dm-core (1.0.2) 
Using dm-do-adapter (1.0.2) 
Installing do_mysql (0.10.2) with native extensions 
Installing dm-mysql-adapter (1.0.2) 
Using nokogiri (1.4.4) 
Using bundler (1.0.3) 
Your bundle is complete! It was installed into ./vendor/bundle

最良のRailsチュートリアル


Rails for ZombiesというRailsを楽しく学べるサイトで紹介されていたRailsチュートリアルがすごく良い。


Learn Ruby on Rails with the Best Free Online Tutorial | Ruby on Rails Tutorial by Michael Hartl | Softcover.io
screenshot


他の多くのWEB上のチュートリアルでは「10分でWEBアプリが簡単に作れます」というキャッチーな感じで、scaffoldを使用してテストに関しては省かれている。


それに対してこのチュートリアルではRSpecを使用してテストファーストTwitterに似たWEBアプリを作成していく。


テストに関してはWEB画面操作をコードで記述できるwebratやテストデータをコードで記述するFactoryGirlも登場する。


またtapsやannotate-modelsなど地味だけど便利なGemも紹介されている。
しかもGit、Herokuを使用してソースコード管理、デプロイまでフォローしているし、
Rails2.3/3.0の両対応だし、最新バージョンへの更新もされている。


こんなチュートリアルは初めて見た。
英語だけどコードがあるから理解できるしね。
Homeにはサンプルのスクリーンキャストも用意されているのでどんな感じで進めていくのかが分かる。


Rails開発での要素が凝縮されていて最良のチュートリアルだ。

RVM gemsetの自動切り替え

RVMを使っていてgemsetの切り替えは手動だから面倒だなと思っていたら、
使用するgemsetを記述した .rvmrc ファイルをフォルダに置いて、
そのフォルダへ移動すると自動で記述したgemsetに切り替わるとは・・・便利!


gemsetをrails3に自動で切り替えたいとき、
毎回 rvm gemset use rails3 と入力していましたが

$ rvm gemset list

gemsets for ruby-1.8.7-p302 (found in /Users/*****/.rvm/gems/ruby-1.8.7-p302)
global
rails2
rails3

$ rvm gemset use rails3
Now using gemset 'rails3'


もう、そんなことしなくてもいい!


フォルダを作って

$ mkdir test


以下の内容のファイル .rvmrc をtestフォルダに置く。

rvm gemset use 1.8.7@rails3


testフォルダに移動すると初回は下図のように確認してくるが、
ここでyesしておけば次回からは自動で切り替わる。

$ cd test

  ============================================================
  RVM has encountered a not yet trusted .rvmrc file in the
  current working directory which contains the following code:
  ============================================================

rvm gemset use 1.8.7@rails3

  ============================================================
  Trusting an .rvmrc file means that whenever you cd into the
  directory RVM will excecute this .rvmrc script in your shell

  Do you wish to trust this .rvmrc from now on?
  ============================================================
  (y for yes, n for no) >


英語のドキュメンドだから見るの面倒だなとかいって見ないと、
結局面倒なことになってるんだよな。


いい加減学習しろ!>自分

sinatra-simple-navigationを試す その2

前回の続き。

動的ナビゲーション

前回はconfig/navigation.rbファイルに項目を設定したが、動的に設定することもできる。
データベースから読み込むことが多いと思うが、今回は直接コードに記述した。

ハッシュの配列を作る。ハッシュの中身は key, name, url

app.rb

    ...

    configure do
      set :my_items, [
        {:key => :books, :name => 'Books', :url => '/books', :items => [
          {:key => :fiction, :name => 'Fiction', :url => '/books/fiction'},
          {:key => :history, :name => 'History', :url => '/books/history'},
          {:key => :sports,  :name => 'Sports',  :url => '/books/sports'}
        ]},
        {:key => :music, :name => 'Music', :url => '/music', :items => [
          {:key => :rock,        :name => 'Rock',        :url => '/music/rock'},
          {:key => :pop,         :name => 'Pop',         :url => '/music/pop'},
          {:key => :alternative, :name => 'Alternative', :url => '/music/alternative'}
        ]},
        {:key => :dvds, :name => 'Dvds', :url => '/dvds', :items => [
          {:key => :drama,  :name => 'Drama',  :url => '/dvds/drama'},
          {:key => :action, :name => 'Action', :url => '/dvds/action'},
          {:key => :comedy, :name => 'Comedy', :url => '/dvds/comedy'}
        ]}
      ]
    end

    ...


viewはrender_navigationのitemsに用意した配列を指定する。

views/index.haml

%h1 sample
%hr
= render_navigation(:renderer => :breadcrumbs, :join_with => ' » ',
                    :items => settings.my_items)
%hr
= render_navigation(:expand_all => true, :items => settings.my_items)


あと config/navigation.rb を空ファイルでもいいので用意する。ファイルが存在しないとエラーになってしまった。

続きを読む

sinatra-simple-navigationを試す

sinatraのドキュメントを見ていたら拡張ライブラリの一覧があった。
sinatra-simple-navigationというWebアプリのナビゲーションリンクを簡単に実装できるライブラリを試したのでメモ。

インストール

bundlerを使うと他を汚さないのでうれしい。

Gemfile

source 'http://rubygems.org'
gem 'sinatra-simple-navigation'


bundle install

$ bundle install
Fetching source index for http://rubygems.org/
Installing activesupport (3.0.3) 
Installing simple-navigation (3.0.2) 
Installing sinatra-simple-navigation (3.0.2) 
Using bundler (1.0.3) 
Your bundle is complete! It was installed into /Users/**********************


activesupportとsimple-navigationもインストールされた。
sinatra-simple-navigatorはRails用のsimple-navigationをsinatraで使えるようにしてあるだけみたい。

続きを読む