|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Rails 'render' question
Is it possible to render a template for an action not within the current controller?
e.g., Code:
render :controller => 'different', :action => 'index' If there is both controller_name.rhtml and application.rhtml within the layouts directory, can I specify which layout to use (or alternatively render them within eachother)? |
|
#2
|
||||
|
||||
|
You can access any actionview using
Code:
render :template => 'different/action', :layout => 'mylayout' The layout is optional. Normally the current layout is used. Usually you create a partial view, when you want to reuse some of your code in different actions. It is a much cleaner approach. Code:
# render $RAILSROOT/app/views/lib/_adminheader.rhtml
# using layout 'layouts/thelayout.rhtml'
# through :locals we provide the variables used in the partial
render :partial => 'lib/adminheader',
:locals => { :page => @page, :somevar => @variable },
:layout => 'thelayout'
Take a look here for further documentation. bye grande |
|
#3
|
|||
|
|||
|
Perfect, thanks!
|
|
#4
|
|||
|
|||
|
OK, one more question:
If I call Code:
render :template => 'different/action' This will not execute the controller code for the called action, but will only render the view of that action (using locals, etc. from the currently executing action). OTOH, if I call Code:
render_component :controller=> 'different', :action => 'action', :params => params This both executes the controller action for 'different/action' and renders the view of that action (using locals, etc. from the 'different/action' action.) Is that correct? |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Ruby Programming > Rails 'render' question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|