[AWDwR4] Iteration A ~ D 中遇到的问题汇总

   Q1. 创建工程后,使用rails server启动web server出错:

  

root@ubuntu:/home/csd/railsProjects/demo# rails server
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)

 

  解决办法
     step 1. 在Gemfile中添加 gem 'therubyracer';//添加therubyracer 这个gem的依赖,Embed the V8 Javascript interpreter into Ruby.
     step 2. 执行 bundle install  //安装Gemfile中指定的Gem

 

Q2. Iteration A2 中,使用

 <%= stylesheet_link_tag :all %> 

 

时,log/development.log中显示
   

Started GET "/assets/all.css" for 10.108.166.253 at 2012-10-25 15:36:44 +0800
    Served asset /all.css - 404 Not Found (4ms)

 

  原文的中这句话的意思是加载public/stylesheets下面的所有的CSS文件。
    If the asset pipeline is disabled, the all option links every CSS file in public/stylesheets
    但由于Rails 3.2 中使用了 Asset Pipeline,导致引用CSS的位置不是原来的public/stylesheets 而是 app/assets/stylesheets, 同时这句话不再是原来的加载所有CSS文件的意思,而是加载all.css这个文件,所以导致找不到all.css这个资源,如同log中的信息提示一样。

  解决办法:
    把depot.css 放到app/assets/stylesheets目录下,app/views/layouts/application.html.erb 这个文件不要动,既不要按照书上那样修改。
    
    ps: 关于 image_tag 中图片路径问题:参考
        如果"1.jpg"放在app/assets/images下面,那就 image_tag("images/1.jpg") 就行了
        如果"1.jpg"放在public/images下面(书中的例子),应该是 image_tag("/images/1.jpg")

 

Q3. Iteration D3 中 添加完Add to Cart 按钮之后,刷新网页,会显示错误:
 

ActiveModel::MassAssignmentSecurity::Error in LineItemsController#create
Can't mass-assign protected attributes: product


    解决办法:
     在 models/line_item.rb 中,添加如下语句
        attr_accessible :product 参考1    参考2  

  另外还有几个解决办法,可参考 cart problem

在 Iteration E1,p140页 执行rake db:migrate时,还会遇到 Can't mass-assign protected attributes: quantity 的错。
       

 回到本系列的目录

posted on 2012-10-27 17:05  生栋  阅读(399)  评论(0编辑  收藏  举报

导航