/Users/yoo/src/lavish/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end (SyntaxError)
そもそも、Rails3 x Ruby1.9.2 のちゃんと構築をしていないので怒られながらメモ$ sudo gem install rvm
でうまくいかないので、$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
.bash_profile に書き込み$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
確認したらbashの読み込みsource ~/.bash_profile
※複数ターミナルを起動していると誤動作するので、全てのターミナルで再ログインが安全 ※追記 MBAでやったら上記の方法でうまくいかなかったので、一旦Homebrewを削除、再インストールして「Installing RVM」を参照にした。$ curl -L get.rvm.io | bash -s stable $ source ~/.rvm/scripts/'rvm'
rvm requirements
どうやらXcode4.3 は根本的にruby 1.9.3が必要みたいです。Xcode 4.3+ users - please be warned - only ruby-1.9.3-p125+ is partially supported - in case of any compilation issues: * downgrade to Xcode 4.1 * uninstall Xcode and install osx-gcc-installer
$ rvm get latest $ rvm pkg install readline $ rvm install 1.9.3 --with-openssl-dir=$rvm_path/usr
$ ruby -v ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
$ bundle install An error occured while installing rmagick (2.13.1), and Bundler cannot continue. Make sure that `gem install rmagick -v '2.13.1'` succeeds before bundling.
rmagick がないのか?と思いきや、$ gem install rmagick
してもエラーになる。 どうやらHomebrewを利用しているので、ImageMagickをインストールするがうまくいかないようです。 ネットで「RMagick のインストールでコケる問題」や「MacでImageMagick+RMagickを使う」などを参考にゴニョゴニョしてみる。$ brew doctor Warning: Your compilers are different from the standard versions for your Xcode. If you have Xcode 4.3 or newer, you should install the Command Line Tools for Xcode from within Xcode's Download preferences. Otherwise, you should reinstall Xcode. Warning: Your Xcode is configured with an invalid path. You should change it to the correct path. Please note that there is no correct path at this time if you have *only* installed the Command Line Tools for Xcode. If your Xcode is pre-4.3 or you installed the whole of Xcode 4.3 then one of these is (probably) what you want: sudo xcode-select -switch /Developer sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Xcode4.3で Developerが削除されたとかの関係(?)、そして gemsのパスも変わっているみたいです。 念のため、Xcode4.3 の仕様どおりのパスにした。sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
また、rvm/gemsのパスも異なる模様。/Users/ユーザ名/.rvm/gems/
以上の事から、imagemagickの再インストールをしてみる。$ brew uninstall little-cms $ brew install little-cms $ brew uninstall imagemagick $ brew install -f imagemagick --disable-openmp
1番のポイントは「-f imagemagick --disable-openmp」とすることでした(多分)。 あとは、rmagickのパーミッションやオーナーの問題(権限がない場合)もありました。sudo chown -R ユーザ名 rmagick-2.13.1
そんなこんなで、rmagick をインストール$ gem install rmagick $ bundle install
できた!ってことで「Lavish」でBootstrapをつくってみた。$ rails new rails_test $ cd rails_test $ ls -al -rw-r--r-- 1 yoo yoo 36 2011-07-17 00:38 .gitignore -rw-r--r-- 1 yoo yoo 743 2011-07-17 00:38 Gemfile -rw-r--r-- 1 yoo yoo 1660 2011-07-17 01:06 Gemfile.lock -rw-r--r-- 1 yoo yoo 9126 2011-07-17 00:38 README -rw-r--r-- 1 yoo yoo 269 2011-07-17 00:38 Rakefile drwxr-xr-x 7 yoo yoo 4096 2011-07-17 00:38 app drwxr-xr-x 5 yoo yoo 4096 2011-07-17 00:38 config -rw-r--r-- 1 yoo yoo 159 2011-07-17 00:38 config.ru drwxr-xr-x 2 yoo yoo 4096 2011-07-17 00:38 db drwxr-xr-x 2 yoo yoo 4096 2011-07-17 00:38 doc drwxr-xr-x 3 yoo yoo 4096 2011-07-17 00:38 lib drwxr-xr-x 2 yoo yoo 4096 2011-07-17 00:38 log drwxr-xr-x 5 yoo yoo 4096 2011-07-17 00:38 public drwxr-xr-x 2 yoo yoo 4096 2011-07-17 00:38 script drwxr-xr-x 7 yoo yoo 4096 2011-07-17 00:38 test drwxr-xr-x 6 yoo yoo 4096 2011-07-17 00:38 tmp drwxr-xr-x 3 yoo yoo 4096 2011-07-17 00:38 vendor
ここら辺ファイル構成は、MVCに慣れてれば問題ないでしょう。 次に、DBを設定してアプリを起動。$ bundle install Fetching source index for http://rubygems.org/ Using rake (0.9.2) Using abstract (1.0.0) ... $ sudo gem instal sqlite3 $ rails server
ブラウザからポート3000 でアクセスする。$ rails generate controller tasks index create app/controllers/tasks_controller.rb route get "tasks/index" invoke erb create app/views/tasks create app/views/tasks/index.html.erb invoke test_unit create test/functional/tasks_controller_test.rb invoke helper create app/helpers/tasks_helper.rb invoke test_unit create test/unit/helpers/tasks_helper_test.rb
config/routes.rb にURLアクセス制御の関数が記述されている。RailsTest::Application.routes.draw do
get "tasks/index"
end
この状態で http://host:3000/tasks/index でアクセスでき、
RailsTest::Application.routes.draw do
resources :tasks, :only => [ :index ]
end
と書き換えると、index を除いた http://host:3000/tasks でアクセスできます。
これは便利!
個別のビュー:app/コントローラ名/ビューファイル.erb レイアウト:app/views/layouts/application.html.erb
を修正してやるだけです。 ちなみに「app/views/layouts/コントローラ名.html.erb」レイアウトファイルを作成すると優先して利用されます。 ※application.html.erb は Rails 3.0 で自動作成されるようになったそうです
<%= render 'ディレクトリ名/footer' %>
# aptitude update # aptitude safe-upgrade # aptitude install libssl-dev zlib1g-dev libreadline6-dev # aptitude install libsqlite3-dev # aptitude install ruby # aptitude install ruby1.9.1 # aptitude install ruby1.9.1-dev # ruby -v ruby 1.8.7 (2010-08-16 patchlevel 302) [i486-linux]
ruby でインストールすると 1.8.7 になったので、切り替え設定をする。 # update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.8 0 # update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 1選択肢 パス 優先度 状態 ------------------------------------------------------------ * 0 /usr/bin/ruby1.9.1 1 自動モード 1 /usr/bin/ruby1.8 0 手動モード 2 /usr/bin/ruby1.9.1 1 手動モード 現在の選択 [*] を保持するには Enter、さもなければ選択肢の番号のキーを押してください: 0 # ruby -v ruby 1.9.2p0 (2010-08-18 revision 29036) [i486-linux]
# aptitude install rubygems # gem install rubygems-update Successfully installed rubygems-update-1.8.5 # gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n # gem install rails ... Successfully installed railties-3.0.9 Successfully installed rails-3.0.9 11 gems installed ...
インストールすると途中でエラー??File not found: lib
gem のパッケージ一覧を確認# gem list ... rack-test (0.6.0, 0.5.7) rails (3.0.9, 3.0.0) railties (3.0.9, 3.0.0) rake (0.9.2) ...
うーん、インストールされている。# gem which rails /var/lib/gems/1.8/gems/railties-3.0.9/lib/rails.rb
しかし、rails のパスが通っていなかったり、‘File not found: lib’ エラーがでる。# cd var/lib/gems/1.8/gems # gem install rdoc-data # gem rdoc --all --overwrite # cd /var/lib/gems/1.8/gems/rails-3.0.9 # mkdir lib # gem rails install
$ vi ~/.bashrc export GEM_HOME=/var/lib/gems/1.8/ export PATH=$PATH:/var/lib/gems/1.8/bin export RUBYLIB=$RUBYLIB:/var/lib/gems/1.8/lib $ rails -v Rails 3.0.9
何かしらエラーがでたら「RailsエラーQA - Ruby」が参考になるかも。