代码改变世界

web敏捷之道 Ajax

2013-07-26 23:15 张小萌 阅读(...) 评论(...) 编辑 收藏

一些和当时版本不同的问题:            (转载)

1.Routing Error 
No route matches [GET] "/assets/depot.css" 
No route matches [GET] "/assets/logo.png" 
Try running rake routes for more information on available routes. 

原因:是由于Rails3.1以后Asset Pipeline默认是开着的,这样helper生产的连接不是以前public/javascripts而是/assets/javascripts/,同理/images和/stylesheets. 
http://guides.rubyonrails.org/layouts_and_rendering.html#asset-tag-helpers 

引用
If you are using Rails with the Asset Pipeline enabled, this helper will generate a link to /assets/javascripts/ rather than public/javascripts which was used in earlier versions of Rails. This link is then served by the Sprockets gem, which was introduced in Rails 3.1.



而这时assets目录在这三个目录任何一个下面即可:app/assets, lib/assets or vendor/assets 

http://guides.rubyonrails.org/asset_pipeline.html 

引用
Pipeline assets can be placed inside an application in one of three locations: app/assets, lib/assets or vendor/assets.



解决:rubyform上有人答复推荐降低rails版本到3.0.5,这个算是个快的解决办法,但总觉得没解决问题,回头用新的开发还是会遇到。其实可以很简答解决问题: 
在app/assets下的对应目录加入相应的css,js,pic即可
 

  1. C:\Ruby193\work\depot\app\assets 的目录  
  2.   
  3. 2012/03/13  13:52    <DIR>          .  
  4. 2012/03/13  13:52    <DIR>          ..  
  5. 2012/03/13  13:35    <DIR>          images  
  6. 2012/03/13  09:58    <DIR>          javascripts  
  7. 2012/03/13  13:52    <DIR>          stylesheets  




2.Ajax无渐变效果(Highlighting Changes) 
error:Missing template line_items/create, application/create 

原因:3.1以后变化 
解决: 
1.\app\views\layouts\application.html.erb 
<%= javascript_include_tag :defaults %> to <%= javascript_include_tag "application" %> 
2.app/views/line_items/create.js.rjs 成create.js.erb,并修改内容: 

  1. page.replace_html('cart', render(@cart))  
  2.   
  3. page[:current_item].visual_effect :highlight,  
  4.                                   :startcolor => "#88ff88",  
  5.                                   :endcolor => "#114411"  
  6.  改成  
  7. $('#cart').html("<%= escape_javascript(render(@cart)) %>");  
  8.   
  9. $('#current_item').css({ 'background-color'"#88ff88" }).animate({ 'background-color'"#114411" }, 1000); //在jquery中animate不支持background-color,所以看不到变回去的动画效果,如果要实现得加载jquery.color.js,详情见官网api  




3.隐藏提交订单后的提示信息(Iteration G1: Capturing an Order) 

  1. app/views/line_items/create.js.erb  
  2. page.select("#notice").each { |notice| notice.hide}  
  3. 改成  
  4. $('#notice').hide();  



4.well-paginate出错(Iteration G3: Pagination) 
error: 
NoMethodError: undefined method `paginate' for 

原因:得安装well-paginate,安装完后重启rails server才行 
按官网:(https://github.com/mislav/will_paginate/wiki/Installation) 
在depot\Gemfile添加: 

  1. ## Gemfile for Rails 3, Sinatra, or Merb  
  2. gem 'will_paginate'  


然后: 

  1. bundle install  


接着: 
重启rails server