rails 生成jquery ajax

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 文件, 修改下面的配置:

 

 

Ruby代码
  1. # JavaScript files you want as :defaults (application.js is always included).   
  2.     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"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值