RJS与ActionController

1,可以通过指定render rjs来避免其他模板在rjs前render
def product
  # skip product.rhtml or product.rxml if either exists
  render :action => "product.rjs"


2,可以通过respond_to来指定不同的format
def product
  respond_to do |format|
    format.html {flash["notice"] = 'here is a product'}
    format.js {render :action => "product.rjs"}
    format.xml {render :xml => @product.to_xml}


3,在渲染RJS模板时ActionController会自动skip layouts,所以不用指定:layout => false

4,rendering options
Option        Work with RJS?    Returns Content-Type=text/javascript?
:action         expected                 Yes
:template       expected                 Yes
:file           expected                 Yes
:inline         not useful               No
:partial        not useful               Yes
:text           not useful               No

5,Inline Rendering
def update
  render :update do |page|
    page.replace_html, 'header', :partial => 'header'
  end
end


6,Browser Redirection
render :update do |page|
  page.redirect_to :controller => 'employees', :action => 'list'
end

render :update do |page|
  page.redirect_to 'http://www.shopify.com'
end

你可能感兴趣的:(JavaScript,html,xml,Flash)