2012年5月29日火曜日

開発中のprojectのerbファイルをhamlへ。

まず、プロジェクトルートへ移動します。
で、以下の3行をGemfileに追加。

group :development do
  gem 'erb2haml'
end

Gemfileを保存したら、
$ bundle install

install終わったら、

$ rake haml:convert_erbs

Looking for ERB files to convert to Haml...
Converting: app/views/authors/_form.html.erb... Done!
Converting: app/views/authors/edit.html.erb... Done!
Converting: app/views/authors/index.html.erb... Done!
Converting: app/views/authors/new.html.erb... Done!
Converting: app/views/authors/show.html.erb... Done!
Converting: app/views/books/_book.html.erb... SyntaxError: embedded document meets end of file. near line 3: "\r"
  Use --trace for backtrace.
Failed!
Converting: app/views/books/_form.html.erb... SyntaxError: embedded document meets end of file. near line 3: ""
  Use --trace for backtrace.
Failed!
Converting: app/views/books/edit.html.erb... Done!
<中略>
Converting: app/views/view/simple_format.html.erb... IndexError: index 74 out of string
  Use --trace for backtrace.
Failed!
Converting: app/views/view/truncate.html.erb... Done!

いくつか失敗してるけど、フォーマットの問題と踏んで、気にせず次に行こう。
気になる人は、ちゃんと--traceオプションつけたり、もとのerbファイルを見直しましょう。
#変換失敗した場合は、hamlファイルは生成されてるけど、中身が空です。

それと、erbは残っているみたいなので、不要なら消してね☆
ちなみに、2回目の変換の場合は、差分のみ出力されました。

hamlを使う。

先日から、hamlジェネレータで遊んでいましたが、rails上でサンプルを動かしてみた。

$ rails new hamltest
$ cd hamltest
$ bundle install vendor/bundle

としたら、3行目の書き方は、deprecatedだってさ。
なので、言われた通りにしてみる。

$ bundle install --path vendor/bundle
...
Your bundle is complete! It was installed into ./vendor/bundle

うん、上出来。

で、Gemfile開いて、以下の1行を追加。
gem 'haml-rails'

で、
$ bundle install

からの
$ rails g controller sample index

って打ってみると、


create  app/controllers/sample_controller.rb
       route  get "sample/index"
      invoke  haml
      create    app/views/sample
      create    app/views/sample/index.html.haml
      invoke  test_unit
      create    test/functional/sample_controller_test.rb
      invoke  helper
      create    app/helpers/sample_helper.rb
      invoke    test_unit
      create      test/unit/helpers/sample_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/sample.js.coffee
      invoke    scss
      create      app/assets/stylesheets/sample.css.scss



よしよし、erb -> hamlへと変わっている。
これで、localhost:3000たたいて動けばOK。

また、よくよく見ると、CoffeeScriptまでできるようになっているではないか!
これは、後ほど勉強しますか。

そういや、環境書いてなかったね。
------------------
MacOS Lion
ruby 1.9.2
Rails 3.2.3
------------------

2012年5月26日土曜日

app/views/layout以下の構成

Ruby on Rails3 アプリケーションプログラミングという本を読んで、コーディングできるように勉強してます。
ちょっとはまったので、メモ。
以下の様なErrorが常にでるようになってしまっていたが、原因がわからず。

Started GET "/assets/defaults.js" for 127.0.0.1 at 2011-09-22 10:22:05 +0200
Served asset /defaults.js - 404 Not Found (3ms)
ActionController::RoutingError (No route matches [GET] "/assets/defaults.js"):

色々調べた結果、app/views/layout以下のファイルに問題がある事が判明。
恐らく、ちゃんと設定できていなかったみたい。ここは今度しっかり理解する。
なので、取りあえず、
rails generate scaffold なんたらで、scaffold作ってみて、app/views/layout以下に何のファイルがあるかをチェック。
あら?application.html.erbファイルのみだった。
ここも、本に沿っていじいじしたので、元に戻したら、ちゃんと動くようになりました。

MacでEmacsキーバインド環境を作る。

メモってなかったみたいなので、備忘録。


まず、以下のサイトから、KeyRemap4MacBookと、PCKeyboardHackの2つをダウンロード。


http://pqrs.org/macosx/keyremap4macbook/index.html.ja
http://pqrs.org/macosx/keyremap4macbook/extra.html.ja


PCKeyboardHackを使えば「無変換」「変換」を「英数」「かな」キーにマッピングできるが、ここでは、以下のCapsLockをControl_L(59)と入れ替えるだけにする。



後は、以下のチェックボックスにチェックが入っていなかったら、チェックしておく。



後は、KeyRemap4MacBookをいじれば、Emacsキーバインドに変更できる。
こちらは、設定が細かいので、省略です。

2012年5月15日火曜日

Windows7のUAC(アクセスコントロール)について

こいつのおかげで、インストールがうまくいかなかったので、備忘録。


見た目は正常Installできているのに、起動時に落ちる現象があった。
以下のUACの設定を最低にして、再インストールしたらOKでした。


UACについて


まず、
[スタート]→[コントロールパネル]→[システムとセキュリティ]→[ユーザーアカウント制御設定の変更]の順にクリック
その後、
「ユーザーアカウント制御の設定」ウィンドウが表示されたら、バーを表示しないに設定する。


でOK。


googleさんにきく時は、「windows7 uac 無効」でOK!

2012年5月11日金曜日

コミットミス

完全におかしいでしょ?ってのをコミットしてしまったので、元に戻すためにする事を備忘録として。

まず、環境前提は、Eclipseでsubversiveが基本だけど、リバートする時は、Tortoise使うってやり方。

1.間違ったコミットのリビジョンを調べる。
2.Tortoiseで間違ったコミットをしたファイル(フォルダ)を右クリックして、ShowLog
3.1.で調べたリビジョンを指定して、右クリック後、Revert changes from this revision
4.Eclipseで対象のファイル(フォルダ)を更新
5.確認してsubversiveでコミット

この流れで問題無い。3.でミスコミットの前のリビジョンのファイルがLocalに戻され、かつ、そのファイルがコミット可能な状態になる。

マジ、変な物コミットしないでくれよ、subversive君。
完全に環境壊れてたんだよな、昨日は。。。

2012年5月4日金曜日

CentOSでApacheServer構築

ターミナル開いて、rootになります。
→ suしてパスワード入れる。

んで、以下のコマンドを入れる。

yum -y install httpd

Complete!と共に完了!

ログ↓

# yum -y install httpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
base                                                     | 3.7 kB     00:00     
extras                                                   | 3.5 kB     00:00     
updates                                                  | 3.5 kB     00:00     
updates/primary_db                                       | 3.0 MB     02:51     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-15.el6.centos will be updated
---> Package httpd.x86_64 0:2.2.15-15.el6.centos.1 will be an update
--> Processing Dependency: httpd-tools = 2.2.15-15.el6.centos.1 for package: httpd-2.2.15-15.el6.centos.1.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.2.15-15.el6.centos will be updated
---> Package httpd-tools.x86_64 0:2.2.15-15.el6.centos.1 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package          Arch        Version                        Repository    Size
================================================================================
Updating:
 httpd            x86_64      2.2.15-15.el6.centos.1         updates      813 k
Updating for dependencies:
 httpd-tools      x86_64      2.2.15-15.el6.centos.1         updates       70 k

Transaction Summary
================================================================================
Upgrade       2 Package(s)

Total download size: 882 k
Downloading Packages:
(1/2): httpd-2.2.15-15.el6.centos.1.x86_64.rpm           | 813 kB     00:30     
(2/2): httpd-tools-2.2.15-15.el6.centos.1.x86_64.rpm     |  70 kB     00:02     
--------------------------------------------------------------------------------
Total                                            26 kB/s | 882 kB     00:33     
警告: rpmts_HdrFromFdno: ヘッダ V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
 Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>
 Package: centos-release-6-2.el6.centos.7.x86_64 (@anaconda-CentOS-201112091719.x86_64/6.2)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : httpd-tools-2.2.15-15.el6.centos.1.x86_64                    1/4 
  Updating   : httpd-2.2.15-15.el6.centos.1.x86_64                          2/4 
  Cleanup    : httpd-2.2.15-15.el6.centos.x86_64                            3/4 
  Cleanup    : httpd-tools-2.2.15-15.el6.centos.x86_64                      4/4 

Updated:
  httpd.x86_64 0:2.2.15-15.el6.centos.1                                         

Dependency Updated:
  httpd-tools.x86_64 0:2.2.15-15.el6.centos.1                                   

Complete!

CentOS(VM)にVMwareToolsをInstall

CentOSにVMwareToolsをInstallする。

まず、VMwareFusion → VMwareToolsのアップデート。



んで、VMwareTools-x.x.x-xxxxxx.tar.gz(xはversion)がフォルダから選択できるようになるので、適当な所にコピー。

ターミナル(端末)を起動して、コピーしたところに移動。
そしたら、コピーしたtar.gzファイルを解凍。
こんな感じ。

tar xvzf VMwareTools-x.x.x-xxxxxx.tar.gz

何か聞かれたら、基本的にyes or EnterでOK。
OS再起動したら、うまくInstallできる。

参考ページ:
http://blog.goo.ne.jp/makoto_climb/e/07b07a22ec50a240eea08ba63e732e24