最近一直在想得到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版本兼容性的问题
group :test dogem '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'
undefined method `environment' for nil:NilClass
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'
bundle update
and voila! Things started working again.