2011-02-18 114 views
31

render :action => "new"render :template => "users/new"有什麼區別?我聽說過渲染模板,我們可以使用其他控制器的視圖。它或兩者之間的渲染布局是否有區別?對於渲染:模板,需要定義一個動作還是視圖頁本身就足夠了?渲染:動作和渲染之間的區別:模板

回答

58

沒有區別。
render :template => 'some/thing'render 'some/thing'相同,如果我們在some控制器中,則與render :action => 'thing'相同。

From Ruby On Rails guide;

render :edit 
render :action => :edit 
render 'edit' 
render 'edit.html.erb' 
render :action => 'edit' 
render :action => 'edit.html.erb' 
render 'books/edit' 
render 'books/edit.html.erb' 
render :template => 'books/edit' 
render :template => 'books/edit.html.erb' 
render '/path/to/rails/app/views/books/edit' 
render '/path/to/rails/app/views/books/edit.html.erb' 
render :file => '/path/to/rails/app/views/books/edit' 
render :file => '/path/to/rails/app/views/books/edit.html.erb'