web敏捷之道 Ajax
2013-07-26 23:15 张小萌 阅读(208) 评论(0) 编辑 收藏 举报一些和当时版本不同的问题: (转载)
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
而这时assets目录在这三个目录任何一个下面即可:app/assets, lib/assets or vendor/assets
http://guides.rubyonrails.org/asset_pipeline.html
解决:rubyform上有人答复推荐降低rails版本到3.0.5,这个算是个快的解决办法,但总觉得没解决问题,回头用新的开发还是会遇到。其实可以很简答解决问题:
在app/assets下的对应目录加入相应的css,js,pic即可
- C:\Ruby193\work\depot\app\assets 的目录
- 2012/03/13 13:52 <DIR> .
- 2012/03/13 13:52 <DIR> ..
- 2012/03/13 13:35 <DIR> images
- 2012/03/13 09:58 <DIR> javascripts
- 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,并修改内容:
- page.replace_html('cart', render(@cart))
- page[:current_item].visual_effect :highlight,
- :startcolor => "#88ff88",
- :endcolor => "#114411"
- 改成
- $('#cart').html("<%= escape_javascript(render(@cart)) %>");
- $('#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)
- app/views/line_items/create.js.erb
- page.select("#notice").each { |notice| notice.hide}
- 改成
- $('#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添加:
- ## Gemfile for Rails 3, Sinatra, or Merb
- gem 'will_paginate'
然后:
- bundle install
接着:
重启rails server