1,可以通过指定render rjs来避免其他模板在rjs前render
[code]
def product
# skip product.rhtml or product.rxml if either exists
render :action => "product.rjs"
[/code]
2,可以通过respond_to来指定不同的format
[code]
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}
[/code]
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
[code]
def update
render :update do |page|
page.replace_html, 'header', :partial => 'header'
end
end
[/code]
6,Browser Redirection
[code]
render :update do |page|
page.redirect_to :controller => 'employees', :action => 'list'
end
render :update do |page|
page.redirect_to 'http://www.shopify.com'
end
[/code]
[code]
def product
# skip product.rhtml or product.rxml if either exists
render :action => "product.rjs"
[/code]
2,可以通过respond_to来指定不同的format
[code]
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}
[/code]
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
[code]
def update
render :update do |page|
page.replace_html, 'header', :partial => 'header'
end
end
[/code]
6,Browser Redirection
[code]
render :update do |page|
page.redirect_to :controller => 'employees', :action => 'list'
end
render :update do |page|
page.redirect_to 'http://www.shopify.com'
end
[/code]