&tag(IntelliJ/Rails); *目次 [#r5244286] #contents *参考情報 [#jdf48202] -[[IntelliJ]] *Tips [#pc621388] **既存プロジェクトをインポート [#h5339a6e] -New Projectで既存のrailsフォルダを指定するのがいいようだ。 **rakeタスクを実行する [#cac74502] -OPT+R or Tools→Run Rake Taskより実行。 **railsスクリプトをデバッグする [#h672492d] -通常のRubyスクリプトのデバッグ用設定を追加し、Ruby scriptをrailsスクリプトに、Script artumentsをrailsスクリプトの引数にする。bundlerを使ってみる場合、Bundelerタブの設定にもチェック。 -デバッグ用のgemをGemfileに入れる必要なし(むしろ入れると動かなくなる)。 **Edit Configuration [#g576873d] -Edit ConfigurationでRailsを選択。 --Server: default --IP address: 0.0.0.0 --Port: 3000 --Server arguments: 空白 --Environment: development --Bundlerの、Run the script…にチェック。 *トラブルシューティング [#fe4cec7b] **Modelのフィールドが見つからないと警告される [#q15ba4c7] -schema.rbが存在しないと言われる。テーブルを独自に作ってscheme.rbが存在しない場合dumpしてやればよい。OPT+R でdb:schema:dump を実行。 **RSpecが実行/デバッグできない [#g9d97b0a] -[[Can not run specs in RubyMine: RSpec support is disabled even though I have rspec-rails gem installed in app's bundle : RUBY-13450:http://youtrack.jetbrains.com/issue/RUBY-13450#tab=History]]が影響?よくわからん。 -無理にIDEのなかから実行するのをやめて、コマンドラインで結果を見るようするという手もある(そのほうが速いし)。[[Rails3+Guard+Spork+RSpec]] -試行錯誤した結果、完全にrailsを入れていないクリーンなruby環境だとテストできないっぽいことがわかった。gemでrailsとrspec-railsをインストールすればテストできた。 #pre{{ gem install rails --version "=3.2.13" gem install rspec-rails }} **rails runnerが実行/デバッグできない [#k054dada] -これもよくわからず。Gemfileでgem 'debugger'すればdebugできるが、ruby-debugと衝突する? **ruby-debug-ideでエラー [#vaece659] -ruby-debug-base19xをインストールすれば消えるっぽい。 ***インストール方法1 [#v85f10af] -[[How do I install ruby-debug-base19x on Mountain Lion for IntelliJ? - Stack Overflow:http://stackoverflow.com/questions/11732715/how-do-i-install-ruby-debug-base19x-on-mountain-lion-for-intellij]]の方法を使う。ruby-debug-base19x -v 0.11.30.pre10だけでいいかも。 #pre{{ gem install ruby-debug-base19x -v 0.11.30.pre10 gem install ruby-debug-ide -v 0.4.17.beta14 curl -L "http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem" -o /tmp/linecache19-0.5.13.gem gem install /tmp/linecache19-0.5.13.gem }} ***インストール方法2[#z7c2f731] -デバッグしようとすると自動でインストールしてくれる(自分で入れる方法は不明)。 -自動インストールで失敗した場合、次のようにしてターミナルからインストールする(--preが重要)。 $ gem install ruby-debug-base19x --pre -homebrewのときは次のようにしてインストール? $ gem install ruby-debug-base19x -v 0.11.30.pre3 **ruby-debugでエラー [#e3c70076] -Gemfileでdebuggerを入れるとエラーになるらしい(衝突)。急にIDEでデバッグできなくなったりした。 -~/.gemにいろいろ入れているみたいなので一旦消してIntelliJを起動しなおす。 **MiniTestでエラー [#f6d45b3b] -次のようなエラーが表示される。 #pre{{ MiniTest framework was detected. It is a lightweight version of original Test::Unit framework. RubyMine/IDEA Ruby plugin test runner requires 'minitest-reporters' (>= 0.5.0) for integration with MiniTest framework (see http://www.jetbrains.com/ruby/webhelp/minitest.html). Or you can use full-featured Test::Unit framework version, provided by 'test-unit' gem, otherwise default console tests reporter will be used instead. }} -[[MiniTest:http://www.jetbrains.com/ruby/webhelp/minitest.html]]と、[[Intellij11とrails(3系)でテストが動かない場合の対処法 - しおしおの雑記帳:http://siosio.hatenablog.com/entry/2012/08/04/161318]]が参考になる。 -Gemfileを修正。 #pre{{ group :test do if RUBY_PLATFORM =~ /(win32|w32)/ gem "win32console", '1.3.0' end gem "minitest" gem "minitest-reporters", '>= 0.5.0' end }} -test/test_helper.rbを修正。 #pre{{ ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require 'minitest/reporters' MiniTest::Reporters.use! class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting fixtures :all # Add more helper methods to be used by all tests here... end }} ** No Rails found in SDK [#p82a9eb8] -デバッグしようとしたら発生。 -SDKを指定しなおしただけではだめで、再起動必要。debug用gemをインストールしたあと起動できた。