CaiDeHen 发表于 2013-2-7 15:07:20

#43 AJAX with RJS

This episode will walk you through adding AJAX functionality to a form using RJS. See how to easily update multiple elements on a page.
<!-- layouts/application.rhtml --><%= javascript_include_tag :defaults %><!-- products/show.rhtml --><% form_remote_for :review, :url => reviews_path, :html => { :id => 'review_form' } do |f| %># reviews_controller.rbdef 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.jsendend# create.rjspage.insert_html :bottom, :reviews, :partial => 'review', :object => @reviewpage.replace_html :reviews_count, pluralize(@review.product.reviews.size, 'Review')page[:review_form].resetpage.replace_html :notice, flash[:notice]flash.discard
页: [1]
查看完整版本: #43 AJAX with RJS