`
hideto
  • 浏览: 2678873 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Rails宝典之第四十三式: Ajax with RJS

    博客分类:
  • Ruby
阅读更多
来看看RJS的应用

我们首先要加上*.js文件,如修改application.rhtml:
<%= javascript_include_tag :defaults %>

然后给Review的create方法加上js格式的应答:
def create
  @review = Review.create!(params[:review])
  flash[:notice] = "Thank you for reviewing this product"
  respond_to do |format|
    format.html { redirect_to product_path(@review.product_id) }
    format.js
  end
end

我们在创建Review的页面中使用form_remote_for:
<!-- products/show.rhtml -->
<% form_remote_for :review, :url => reviews_path, :html => { :id => 'review_form' } do |f| %>
...
<% end %>

最后就是写create.rjs文件了:
page.insert_html :bottom, :reviews, :partial => 'review', : object => @review
page.replace_html :reviews_count, pluralize(@review.product,reviews.size, 'Review')
page[:review_form].reset
page.replace_html :notice, flash[:notice]
flash.discard

没多大新意,学习RJS看<<RJS Templates for Rails>>即可
分享到:
评论

相关推荐

    跨越边界1:Ajax on Rails

    【标题】:“跨越边界1:Ajax on Rails” 【描述】:本文主要探讨了Ajax技术如何与Ruby on Rails框架相结合,创造出高度交互性的Web应用。Ajax技术利用XML、JavaScript和Web标准,通过异步通信增强用户体验,而Ruby...

    Rails的精简版本Rails::API.zip

    Rails::API 是 Rails 的精简版本,针对不需要使用完整 Rails 功能的开发者。 Rails::API 移除了 ActionView 和其他一些渲染功能,不关心Web前端的开发者可更容易、快速地开发应用程序,因此运行速度比正常的 Rails ...

    Rails上的API:使用Rails构建REST APIAPIs on Rails: Building REST APIs with Rails

    在本篇内容中,我们将深入探讨如何利用Ruby on Rails(简称Rails)这一强大的Web应用程序框架来构建可伸缩且易于维护的RESTful API。Rails以其简洁优雅的语法、高效的开发速度以及良好的社区支持而闻名,这使得它...

    Ajax on Rails

    This book teaches intermediate to advanced web developers how to use both Ajax and Rails to quickly build high-performance, scalable applications without being overwhelmed with thousands of lines of ...

    Ajax on Rails (PPT)

    #### 七、示例:Ajax Sea 文档提到了一个示例——“Ajax Sea”,但未给出详细内容。根据上下文推测,“Ajax Sea”可能是文档中用来演示如何利用Rails和Prototype实现Ajax功能的一个具体案例。该示例可能会涵盖以下...

    RJS Templates for Rails

    RJS templates are an exciting and powerful new type ... This document helps you get acquainted with how RJS templates fit into the Rails framework and gets you started with a few easy-to-follow examples.

    CakePHP :: Ajax Demo

    This is a simple demo of some of the AJAX helpers now available in CAKE. These helpers are directly modeled on Ruby On Rails. In fact, they were shamelessly ported from rails almost verbatim. You can ...

    Beginning Google Maps Applications with Rails and Ajax

    综上所述,《Beginning Google Maps Applications with Rails and Ajax》这本书为初学者提供了一条清晰的学习路径,从基础概念到实践案例,全面覆盖了如何使用Google Maps API、Rails以及Ajax技术创建高质量的地图...

    Rails中应用Ext.tree:以中国的省市地区三级联动选择为例

    在Ruby on Rails(Rails)框架中,开发人员经常需要实现各种...通过学习这个实例,开发者可以掌握如何在Rails应用中集成第三方库,处理层级数据,以及创建交互式的前端界面。这对于提升Web应用的用户体验非常有价值。

    rjs 技术

    rjs,全称Ruby JavaScript,是一种在Ruby on Rails框架中结合JavaScript的编程方式,主要用于创建动态和交互式的网页应用。它允许开发者使用Ruby语法来编写JavaScript代码,使得JavaScript的编写更加简洁、易读,...

    Beginning Google Maps Applications with Rails and Ajax: From Novice to Professional (part2)

    Beginning Google Maps Applications with Rails and Ajax: From Novice to Professional

    Beginning Google Maps Applications with Rails and Ajax: From Novice to Professional (part1)

    Beginning Google Maps Applications with Rails and Ajax: From Novice to Professional

    跨越边界 Ajax on Rails

    **Ajax on Rails:跨越边界的Web交互技术** Ajax(Asynchronous JavaScript and XML)技术的引入,为Web应用程序带来了革命性的变化,它使得页面无需刷新就能实现数据的动态更新,极大地提升了用户体验。Rails作为...

    ajax on rails

    ajax on rails压缩包,全英文

    Agile+Web+Development+with+Rails中文版.pdf

    在《Agile Web Development with Rails》中,读者可以学习到如何运用敏捷方法来规划项目,实施增量式开发,并通过频繁的反馈来提高产品质量。 Ruby on Rails(简称Rails)是一个基于Ruby语言的开源Web开发框架,它...

    Agile Web Development with Rails 4

    Ruby on Rails helps you produce high-quality, beautiful-looking web applications quickly. You concentrate on creating the application, and Rails takes care of the details., Tens of thousands of ...

Global site tag (gtag.js) - Google Analytics