1:rails new sample -T 不生成测试目录
2:生成jqeury自动移除protype:
rails new hel -J
gem "jquery-rails"
bundle install
rails g jquery:install 可以加上: 或者--ui
3: rails 3用mysql 加上gem mysql2" 修改yml文件
rails3中 不适用link_to_remote form_remote:
#==========
1. 让Rails3使用jQuery
轻量级js框架jquery相信大家一定不会陌生, 本教程中的ujs教程也是基于jquery来写的(当然你也可以使用prototype).
首先, 下载最新的jquery然后放入 public/javascripts 文件夹下面:
$ curl -L http://code.jquery.com/jquery-1.4.3.min.js > public/javascripts/jquery.js
同时我们也需要把原来的prototype ujs的rails.js 改成 jquery-ujs的rails.js:
$ curl -L http://github.com/rails/jquery-ujs/raw/master/src/rails.js > public/javascripts/rails.js
下载后可以看下javascripts文件夹, 里面有application, controls, dragdrop, effects, jquery, prototype 以及 rails 等js文件, 出来jquery以外, 其他都是生产bolg应用时rails加进去的.
现在打开 config/application.rb 文件, 修改下面的配置:
- # JavaScript files you want as :defaults (application.js is always included).
- config.action_view.javascript_expansions[:defaults ] = %w(jquery rails)
# JavaScript files you want as :defaults (application.js is always included). config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
上面的代码告诉rails, :default 符号的定义现在改成 jquery和rails啦, 启动我们的博客程序, 查看源代码中的<head>中的<script>是不是这3个js脚本.
#==========
rails2:
link_to_remote 'delete', :url => admin_image_path(image), :confirm => 'Are you sure you want to delete this image?', :method => :delete
rails3:
link_to "Delete", admin_image_path(image), :method=>:delete, :confirm=>"Are you sure you want to delete this image?", :remote=>:true, :class=>"alert"