Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rails3.2 misc
- =============
- Author: @libkinjo
- Date: 2012-05-12 12:39:41 JST
- Table of Contents
- =================
- 1 rails プロジェクト開始直後(rails new の直後)にやること
- 2 rails3.2 をインストールする前にインストールしておくとよい rubygems
- 3 ruby 1.9.3 で ruby-debug19 をインストールする
- 4 rails3.2 インストール
- 5 i18n_generators 日本語化 - validation メッセージとモデルのフィールド名
- 6 i18n_generators 日本語化 - 日本語化されたモデルのフィールド名を取得
- 7 coffeescript を使う
- 8 coffeescript ではなく javascript ファイル(.js) を使いたい場合
- 9 posts.js.coffee と posts.js が両方存在する場合の動作 => 期待通りの動作にならない
- 10 sass http://sass-lang.com/
- 11 情報(ガイド) http://guides.rubyonrails.org/
- 12 ruby-debug エラー: ruby_debug.so: undefined symbol: ruby_current_thread - (LoadError)
- 13 file 'lib' not found と表示されてインストールできない
- 14 Could not find a JavaScript runtime と表示されて rails s できない
- 1 rails プロジェクト開始直後(rails new の直後)にやること
- ---------------------------------------------------------
- git を使用するため、 git init で初期化し、 git commit で初期コミットしておく。
- git init
- git add .
- git commit -m 'init'
- therubyracer 有効化する。 (Gemfile の以下の行をコメントインし bundle install を実行する。)
- gem 'therubyracer', :platform => :ruby
- ruby-debug19 有効化する。 (Gemfile の以下の行をコメントインし bundle install を実行する。)
- gem 'ruby-debug19', :require => 'ruby-debug'
- pry 関連の設定。
- Gemfile の group :development, :test ブロック中に、以下のように 設定する。 (Gemfile 編集後に bundle install を実行する。)
- group :development, :test do
- gem 'pry-rails'
- gem 'pry-doc'
- end
- bundle install
- ruby-debug のために、以下も実行しておく。(必要ないかも?)
- bundle update ruby-debug-base19
- ここまで git commit する。
- git add .
- git commit -m 'install pry'
- haml 関連の設定。
- 以下を実行して Gemfile を編集する。(Gemfile 編集後に bundle install を実行する。)
- echo "gem 'haml-rails'" >> Gemfile
- echo "gem 'coffee-filter'" >> Gemfile
- html2haml を使うため、以下を実行して haml をインストールする。
- gem install haml --no-ri --no-rdoc
- gem install hpricot --no-ri --no-rdoc
- gem install ruby_parser --no-ri --no-rdoc
- rbenv rehash を実行し html2haml を使えるようにする。
- rbenv rehash
- html2haml を実行し application.html.erb を application.html.haml へ変換する。
- html2haml -e app/views/layouts/application.html.erb app/views/layouts/application.html.haml
- git add .
- git rm app/views/layouts/application.html.erb
- git commit -m 'move app/views/layouts/application.html.erb to application.html.haml'
- rspec, spork ([https://github.com/sporkrb/spork-rails]) 関連の設定。
- 以下を実行して Gemfile を編集する。
- group :development, :test が既にあればブロック中に以下を追加する。
- group :development, :test がなければ group を追加し、そのブロック中に以下を追加する。
- (Gemfile 編集後に bundle install を実行する。)
- gem 'rspec-rails'
- gem 'spork-rails'
- rspec 関連の設定ファイルを生成する。
- rails g rspec:install
- spork を使用可能とするために rbenv rehash を実行する。
- rbenv rehash
- spork を実行し spork の設定ファイルを生成する。
- spork rspec --bootstrap
- spec/spec_helper.rb を編集する。
- (spec_helper.rb にある # This file is copied to spec/ when you run 'rails generate rspec:install'
- 行より以下のコードを Spork.prefork ブロック中に移動する)
- また Spork.each_run ブロック中に以下を追加する。
- # http://nerian.es/2011/02/28/RPS-3-spork_and_mongoid.html
- load "#{ Rails.root}/config/routes.rb"
- Dir["#{Rails.root}/app/**/*.rb"].each { |f| load f }
- spec/spec_helper.rb のファイル先頭付近にある以下の require 行をコメントインする。
- (アンコメントすると rspec 内での debugger 呼び出しでブレークできなくなる問題があった
- 2012-05-03 木。現状ではコメントアウトしたままの方がいいかもしれない)
- require 'spork/ext/ruby-debug'
- ここまで git commit する。
- echo "TAGS" >> .gitignore
- echo "tags" >> .gitignore
- git add .
- git commit -m 'install rspec and spork'
- factory_girl 関連の設定。
- Gemfile の group :test, :development ブロック中に gem 'factory_girl_rails' を追加する。
- (Gemfile 編集後に bundle install を実行する。)
- gem 'factory_girl_rails'
- spec/spec_helper.rb の Spork.each_run ブロック中に以下を追加する。
- FactoryGirl.reload
- ここまで git commit する。
- git add .
- git commit -m 'setup factory_girl'
- 2 rails3.2 をインストールする前にインストールしておくとよい rubygems
- ---------------------------------------------------------------------
- pry は ruby の調査に役立つ。
- gem install pry --no-ri --no-rdoc
- gem install pry-doc --no-ri --no-rdoc
- haml を使うとき html2haml が役立つ。
- gem install haml --no-ri --no-rdoc
- gem install hpricot --no-ri --no-rdoc
- gem install ruby_parser --no-ri --no-rdoc
- ruby-debug19 をインストールする。
- 3 ruby 1.9.3 で ruby-debug19 をインストールする
- ------------------------------------------------
- gem をとってくる。(ちゃんと取ってこれているか調べる。ファイルが空じゃないかとか)
- wget http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
- wget http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
- wget http://rubyforge.org/frs/download.php/63094/ruby-debug19-0.11.6.gem
- wget http://rubyforge.org/frs/download.php/74596/ruby_core_source-0.1.5.gem
- RVM_SRC をセットする
- export RVM_SRC=$HOME/.rbenv/versions/1.9.3-p125
- とってきた gem をインストールする。
- HTTP PROXY な環境なら /etc/environment に以下を設定する。
- HTTP_PROXY="http://proxy.co.jp:8080/"
- HTTPS_PROXY="https://proxy.co.jp:8080/"
- gem をインストールする。
- gem install ./ruby_core_source-0.1.5.gem -- --with-ruby-include=/$RVM_SRC --no-ri --no-rdoc
- gem install ./linecache19-0.5.13.gem -- --with-ruby-include=/$RVM_SRC --no-ri --no-rdoc
- gem install ./ruby-debug-base19-0.11.26.gem -- --with-ruby-include=$HOME/.rbenv/versions/1.9.3-p125/include/ruby-1.9.1/ruby-1.9.3-p125 --no-ri --no-rdoc
- gem install ./ruby-debug19-0.11.6.gem -- --with-ruby-include=/$RVM_SRC --no-ri --no-rdoc
- rails プロジェクトで以下を実行する。
- bundle update ruby-debug-base19
- 4 rails3.2 インストール
- ------------------------
- gem install rails --no-ri --no-rdoc
- rbenv を使っている場合、 gem install した後は rbenv rehash すること。
- 5 i18n_generators 日本語化 - validation メッセージとモデルのフィールド名
- -------------------------------------------------------------------------
- Gemfile に以下を追加して bundle install を実行する。
- gem 'i18n_generators'
- rails のエラーメッセージを日本語化するためのファイルを下記コマンドで生成する。
- rails g i18n_locale ja
- config/application.rb を編集する。(以下の行を追加)
- config.i18n.default_locale = :ja
- この段階でエラーメッセージは日本語化されるが、モデルのフィールド名などは
- 日本語化されない。
- モデルのフィールド名を日本語化するためのファイルを下記コマンドで生成する。
- rails g i18n_translation ja
- config/locales/translation_ja.yml が生成される。
- あとは、適宜 config/locales/translation_ja.yml を編集しながら日本語化をすすめていく。
- 6 i18n_generators 日本語化 - 日本語化されたモデルのフィールド名を取得
- ----------------------------------------------------------------------
- Model.human_attribute_name(:field)
- 7 coffeescript を使う
- ----------------------
- rails generate scaffold したとき coffeescript の雛形ファイルが生成される。
- rails g scaffold Post .. を実行した場合は app/assets/javascripts/posts.js.coffee が
- 生成される。
- Post のビューで使用するロジックを app/assets/javascripts/posts.js.coffee に記述する。
- 以下例。
- # Place all the behaviors and hooks related to the matching controller here.
- # All this logic will automatically be available in application.js.
- # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
- $ =>
- $('a').click =>
- alert 'hello'
- return false
- 8 coffeescript ではなく javascript ファイル(.js) を使いたい場合
- ----------------------------------------------------------------
- rails generate scaffold したとき coffeescript の雛形ファイルが生成される。
- 例えば
- rails g scaffold Post .. を実行した場合は app/assets/javascripts/posts.js.coffee が
- 生成される。
- この app/assets/javascripts/posts.js.coffee を削除して
- app/assets/javascripts/posts.js を作成しなおせば、
- app/assets/javascripts/posts.js に
- javascript の記述を行える。
- *.js.coffee と *.js が存在している場合は *.js.coffee が優先して実行される?
- 9 posts.js.coffee と posts.js が両方存在する場合の動作 => 期待通りの動作にならない
- -----------------------------------------------------------------------------------
- jquery のイベントコールバックは二重実行となることを確認した。
- あと posts.js は評価されるが posts.js.coffee は評価されないよう。
- 10 sass [http://sass-lang.com/]
- --------------------------------
- sass の特徴については [http://sass-lang.com/] に掲載されている
- Variables, Nesting, Mixins, Selector Inheritance で理解できる。
- - Variables
- - パラメータ値を変数でもてる
- - 変数は $ 記号から始まる
- - Nesting
- - 文字通り入れ子にできる
- - Mixins
- - @ 記号で Mixins を定義する
- - @include で Mixins する
- - Selector Inheritance
- - @extend で継承する
- 11 情報(ガイド) [http://guides.rubyonrails.org/]
- -------------------------------------------------
- 12 ruby-debug エラー: ruby_debug.so: undefined symbol: ruby_current_thread - (LoadError)
- -----------------------------------------------------------------------------------------
- 以下のように表示され rails s -u できない
- /home/first/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:1:in `require': /home/first/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so: undefined symbol: ruby_current_thread - /home/first/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so (LoadError)
- from /home/first/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:1:in `<top (required)>'
- 以下を参考にして解決
- [http://blog.udzura.jp/2012/02/15/ruby-debug19-install-on-ruby193-p0-and-rvm/]
- 上記を試した記録は次を参照 >>>ruby-debug
- 13 file 'lib' not found と表示されてインストールできない
- ---------------------------------------------------------
- --no-ri --no-rdoc オプションをつけてインストールする
- [http://passingloop.tumblr.com/post/10519067297/file-lib-not-found-when-installing-rails-3-1-on-mac-os-x]
- 14 Could not find a JavaScript runtime と表示されて rails s できない
- ---------------------------------------------------------------------
- 以下のように表示される
- /home/first/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs/runtimes.rb:50:in `autodetect': Could not find a JavaScript runtime. See [https://github.com/sstephenson/execjs] for a list of available runtimes. (ExecJS::RuntimeUnavailable)
- Gemfile にある以下の一行をコメントインする。
- gem 'therubyracer', :platform => :ruby
- 最後に bundle install を実行する。
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement