`
ttitfly
  • 浏览: 620274 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

prototype in rails

阅读更多

1.prototype是rails 的内置javascript库。prototype.js文件默认是在public/javascripts目录下

2..rhtml页面导入prototype.js

  1. <%=javascript_include_tag "prototype"%>  

 

3. link_to_remote使用

在test1.rhtml里发起ajax调用

  1. <%= link_to_remote("Do the ajax thing",:update => 'mydiv',:url => { :action => :say_hello })%>   
  2. <div id="mydiv"> the text will be chanaged</div>  

可以通过查看生成页面的源文件,可以看到这段代码最终生成的为:

js 代码
  1. <a href="#" onclick="new Ajax.Updater('mydiv', '/ajax_test/say_hello', {asynchronous:true, evalScripts:true}); return false;">Do the ajax thing</a>   
  2. <div id="mydiv"> the text will be chanaged</div>  

可以看到要执行ajax_test_controller里的say_hello方法

所以需要定义一个say_hello方法

ruby 代码
  1. def say_hello   
  2.    #不使用任何layout   
  3.     render(:layout => false)   
  4. end  

 

定义对应试图say_hello.rhtml

  1. <em>hello from ajax </em>  

运行即可看到效果

分享到:
评论

相关推荐

    Manning - Prototype.and.Scriptaculous.in.Action

    4. **高级主题**(Part IV - Advanced Topics):这部分讨论了一些高级话题,例如如何在实践中综合运用 Prototype 和 Scriptaculous、如何与 Rails 框架集成等。此外,书中还附带了三个附录,分别介绍了 HTTP 协议...

    介绍ajax开发框架的书《Prototype and Scriptaculous quickly》

    - **第13章:Prototype、Scriptaculous与Rails**:探讨这些库与Ruby on Rails框架的结合使用方法。 此外,书中还包括三个附录,分别涉及HTTP基础知识、测量HTTP流量以及Tomcat安装设置等内容,为读者提供了全方位...

    Prototype1.6 JS 官方下载地址

    - 在 `Learn about what’s new in version 1.6` 这个链接中,用户可以了解到 Prototype 1.6 相比之前版本的新特性、改进和修复的问题。 综上所述,Prototype 1.6 是一个强大的 JavaScript 库,它提供了丰富的功能...

    ASP.NET MVC 2 in Action

    With a prototype demonstration in late 2007 and a key hire of Phil Haack as the Senior Program Manager of the feature team, Mr. Guthrie made the vision a reality. At a time when the .NET community ...

    Kapslock-prototype:kapslock.in网站设计和开发中的原型

    《Kapslock-prototype:构建Kapslock.in网站设计与开发原型详解》 在网站设计与开发的过程中,原型扮演着至关重要的角色。它为设计师和开发者提供了一个清晰的视觉指南,帮助他们理解项目的整体结构、功能和用户...

    Sap Ruby Ajax

    Ruby on Rails provides built-in AJAX functionality through its API over Prototype and Scriptaculous. Let's explore how this integration is implemented using a simple example of locking and unlocking ...

    Aptana.Studio.Professional.v1.2.7.024774.Incl.KeyMaker.and.Patch-DVT.part01.rar

    Aptana是一个基于Eclipse的集成...× prototype/dojo等常见AJAX类库集成和提示 × JSON编辑器 2、Adobe AIR开发环境 3、Apple iPhone开发环境 4、Ruby on Rails开发环境 5、PHP开发环境 6、JavaScript调试器

    Ajax in action(中文版1~8章全部)

    在这一章中,作者列出了当时流行的Ajax库,如Prototype、jQuery等,并分析了它们的优势和适用场景。这些工具库简化了JavaScript编程,让开发者可以更快地构建功能丰富的Ajax应用。 **第6章:Ajax与用户体验** 本章...

    CakePHP :: Ajax Demo

    In fact, they were shamelessly ported from rails almost verbatim. You can also see some of the amazing effects available through the Prototype javascript library. This is a demo not an application...

    javascript框架介绍

    Scriptaculous的优势在于与Prototype的无缝集成,以及在《Ajax in Action》一书中的推荐,但其兴起时间较短,成熟度有待验证。 #### 五、YUI Ext YUI Ext是基于Yahoo UI的扩展框架,专注于构建具有复杂Layout布局...

    gof patterns in ruby

    Prototype模式是一种创建型模式,用于按现有对象创建新对象的同时更改某些属性。这种模式提供了一种替代创建对象的构造函数的新机制。 #### Singleton(单例) 单例模式确保一个类只有一个实例,并提供一个全局...

    Knockout API 中文版

    KO和jQuery (或Prototype等)是竞争关系还是能一起使用? 所有人都喜欢jQuery! 它是一个在页面里操作元素和事件的框架,非常出色并且易使用,在DOM操作上肯定使用jQuery,KO解决不同的问题。 Everyone loves jQuery!...

    21个新奇漂亮的AjaxCSS表格设计

    - **Paginate, sort and search a table with Ajax and Rails**:提供动态界面,避免页面重载,提升用户体验。 - **Collapsible tables with DOM and CSS**:通过DOM操作和CSS控制表格的展开和折叠,适合于复杂数据...

Global site tag (gtag.js) - Google Analytics