天天看點

Ruby on Rails 4 Tutorial Window7系統下出現的問題彙總.

最近一直在想得到ThoughtWorks的工作機會,苦于自己的工作語言是C++,而ThoughtWorks比較常見的技術棧是Java,Ruby等語言,遂為了增加那麼一丢丢拿offer的機會,開始每天下班回來自學<<Ruby on Ralis 4 Tutorial>>這本書,這本書就是做了一個簡單的Twitter。書講的很簡單易懂,完全是上手實戰,加上都是TDD(測試驅動開發)(加分項哦!),讓我這個以前沒做過Web開發的新手都對Web開發有了一定的了解。

書的所有代碼都自己手敲了一遍。覺得這樣對自己提高還是比光看一遍書高很多,推薦大家新學一門語言的時候還是自己動手把代碼敲一遍比較好,因為不自己動手實作一遍,你不會知道這個代碼的運作效果和是否會運作成功。。。。。。為什麼這麼說,因為網上好多人都說新手要學習Ruby on Rails 開發最好用Mac,或者自己裝個虛拟機,因為在Windows下會有一堆各種各樣配置的問題弄得你焦頭爛額。。。。。。我木有mac。。。。。用win7習慣了,也不想弄個虛拟機。。。。是以,學習過程簡直一把辛酸淚。。。。學習過程中經常會碰到一些莫名其妙的問題,弄得你一把辛酸淚。。。。。網上中文的針對Windows下的Ruby on Rails 4中碰到的問題又基本沒有,都是在Stack Overflow上才可能找到,為了讓想用Windows學習Ruby on Rails開發的同學們少浪費點時間在這些出現的莫名其妙的問題上,我将我在學習<<Ruby on Ralis 4 Tutorial>>這本書中遇到的一些配置相關的問題整理了下來。因為問題都是在學習過程中用印象筆記記下的,是以好多都是在Stackoverflow上直接複制下來的答案整理起來的,都是關于gem檔案的。有點亂,大家如果遇到同樣的錯誤,可以吧錯誤截圖給我,我再貼上來,讓後來人能更好的定位問題。

1.Windows 7下運作Ruby on rails時顯示exec的錯誤:經搜尋發現是coffee-script-source版本相容性的問題

Ruby on Rails 4 Tutorial Window7系統下出現的問題彙總.

  2.按書的第三章來做練習,具體在第75頁,輸入bundle exec rspec spec/requests/static_pages_spec.rb 結果提示一大堆問題。      出現zip-zip error時,添加:rubyzip ,出現websocket error時添加

     group :test do

    gem 'rubyzip', '~>0.9.9'

    gem 'websocket', '1.0.7'

    gem 'selenium-webdriver', '2.35.1'

    gem 'capybara', '2.1.0'

end

~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activesupport-4.0.13/lib/active_support/dependencies.rb:229:in `require': cannot load such file -- test/unit/assertions (LoadError)

     添加 

minitest

 gem不成功,添加gem 'test-unit' 成功!

3.Chapter 3.6.2 ERROR

E:\Rails_projects\sample_app>bundle exec guard init rspec 21:39:05 - INFO - Writing new Guardfile to E:/Rails_projects/sample_app/Guardfil e 21:39:05 - ERROR - Could not load 'guard/rspec' or '~/.guard/templates/rspec' or  find class Guard::Rspec 21:39:05 - ERROR - Error is: No such file or directory @ rb_sysopen - C:/Users/A dministrator/.guard/templates/rspec

解決方案:

instead of gem 'guard-rspec', '2.5.0' 

replace on gem 'guard-rspec', '4.6.0' 

instead of gem 'rspec-rails', '2.13.1'

replace on gem 'rspec-rails', '3.3.2'

4. 調試 代碼5.6引入 “booststrap”後運作網頁出現如下問題:

undefined method `environment' for nil:NilClass

  (in E:/Rails_projects/sample_app/app/assets/stylesheets/custom.css.scss)

在stackoverflow上找到答案:

I ran into this exact problem today and managed to solve it.

Funny thing is that yesterday everything was fine (of which I have proof because I pushed a working version to Heroku before going to bed last night), but today things broke after I did 

bundle update

. So I went through the terminal output of that and noticed that the sprockets gem updated to 2.12.0. I then went back and realized that it was 2.11.0 yesterday. Hmm...

On a hunch, I edited my gemfile and added this line:

gem 'sprockets', '2.11.0'
           

Basically, to force bundler to install that specific version. I then did another 

bundle update

 and voila! Things started working again.