Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 23rd, 2007, 10:21 AM
CubanCorona CubanCorona is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 4 CubanCorona User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m
Reputation Power: 0
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)?

Reply With Quote
  #2  
Old July 23rd, 2007, 10:35 AM
grande's Avatar
grande grande is offline
$foo->bar($_);
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Location: London
Posts: 86 grande User rank is Sergeant Major (2000 - 5000 Reputation Level)grande User rank is Sergeant Major (2000 - 5000 Reputation Level)grande User rank is Sergeant Major (2000 - 5000 Reputation Level)grande User rank is Sergeant Major (2000 - 5000 Reputation Level)grande User rank is Sergeant Major (2000 - 5000 Reputation Level)grande User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 19 h 42 m 49 sec
Reputation Power: 52
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

Reply With Quote
  #3  
Old July 23rd, 2007, 01:50 PM
CubanCorona CubanCorona is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 4 CubanCorona User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m
Reputation Power: 0
Perfect, thanks!

Reply With Quote
  #4  
Old July 24th, 2007, 07:29 AM
CubanCorona CubanCorona is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 4 CubanCorona User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m
Reputation Power: 0
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?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Rails 'render' question

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap