Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7403997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:11:32+00:00 2026-05-29T05:11:32+00:00

I am doing the Lynda.com rails tutorial and they explain how to render another

  • 0

I am doing the Lynda.com rails tutorial and they explain how to render another view than the default one using render(‘methodname’).

However, I noticed this rendering is not “nested”. For example, in the code below, localhost:3000/demo/index would generate the view in views/demo/hello.html.erb, while localhost:3000/demo/hello would render the text ‘Hello there’.

Is there a way to have “nested” rendering, i.e. such that requesting demo/index would return ‘Hello there’ in this example?

(Also, some use cases for nested rendering would be nice. I am asking only out of curiosity.)

class DemoController < ApplicationController
  def index
     render ('hello')            
  end

  def hello
    render(:text => 'Hello there')
  end

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:11:32+00:00Added an answer on May 29, 2026 at 5:11 am

    I don’t know what you exactly mean by nested rendering.

    Scenario #1

    If you want action “index” to be triggered but template “hello.html.erb” to be shown, you can do

    def index
      render :action => :hello
    end
    

    This will render the template app/views/demos/hello.html.erb (or other format if you want it to (i.e. specify it in the url)).

    So render :action => :hello is just a shortcut.

    You can also do render :template => "hello.html.erb" or render :file => Rails.root.join("app/views/demos/hello.html.erb") (sometimes useful).

    Scenario #2

    If you want to render that text, you can just call hello method inside index method

    def index
      hello
    end
    

    If you don’t want other stuff from hello action to be run you can separate it to other method, like so:

    def render_hello
      render :text => "Hello world"
    end
    
    def index
      # some other stuff going on...
      render_hello
    end
    
    def hello
      # some other stuff going on...
      render_hello
    end
    

    You can not render twice in the same action.

    Btw the url should not say /demos/index but just /demos.
    Index is the default action for resources route (resources :demos).

    Please select the scenario which suits you (so I can remove unnecessary text from this answer).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am doing a lynda.com Rails essential training tutorial, and I am getting
I am doing the Lynda.com learning PHP 2 videos and have run into a
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing a search using django-sphinx gives me results._sphinx that says there were 68 results,
Doing a some practice questions for exam tomorrow can't figure out this one What
Doing this in a console program: object x = new string(new char[0]); If one
Doing a couple rotations in Matlab, one which is rotation about the y-axis, however
Doing some integration work with another site I've got the unusual requirement of needing
Doing some initial research on a new project and one of my requirements is
Doing DJango 1.3 local development using manage.py runserver Created a directory called static in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.