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 6704391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:17:00+00:00 2026-05-26T07:17:00+00:00

I saw some code in a Rails v2.3 app. In layout/car_general.html.erb (this view is

  • 0

I saw some code in a Rails v2.3 app.

In layout/car_general.html.erb (this view is called by a method in cars_controller) , I saw the code:

<body>
    <%= yield %>

    <%= javascript_include_tag 'jquery-1.4.2.min' %>

    <% javascript_tag do %>
      <%= yield :jstemplates %>
          var some_car = new Object;
      <%= yield :some_car %>
    <% end -%>
</body>

Two questions to ask:

  1. Where can I find the yield content of the first <%=yield%> under <body>.
  2. Is it a rails specific way to include js code in a view by using
    <%= yield :jstemplates %> and what about <%= yield :some_car %> , is it point to a view or just to show the value of some_car?
  • 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-26T07:17:00+00:00Added an answer on May 26, 2026 at 7:17 am

    Without any arguments, yield will render the template of the current controller/action. So if you’re on the cars/show page, it will render views/cars/show.html.erb.

    When you pass yield an argument, it lets you define content in your templates that you want to be rendered outside of that template. For example, if your cars/show page has a specific html snippet that you want to render in the footer, you could add the following to your show template and the car_general layout:

    show.html.erb:

    <% content_for :footer do %>
      This content will show up in the footer section
    <% end %>
    

    layouts/car_general.html.erb

    <%= yield :footer %>
    

    The Rails Guide has a good section on using yield and content_for: http://guides.rubyonrails.org/layouts_and_rendering.html#understanding-yield

    The API documentation for content_for is helpful too and has some other examples to follow. Note that it’s for Rails 3.1.1 , but this functionality has not changed much since 2.3, if at all and should still apply for 3.0.x and 3.1.x.

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

Sidebar

Related Questions

I saw some code, html form code which looks like this: <form name=form1 method=post
I saw some code like this: try { db.store(mydata); } finally { db.cleanup(); }
const static int foo = 42; I saw this in some code here on
I saw some code written by another developer that looks something like this: var
I recently saw some code that reminded me to ask this question. Lately, I've
I saw some code yesterday in this question that I had not seen before,
I saw some code that called methods on scalars (numbers), something like: print 42->is_odd
Just now,I saw some code like this: if(condition){ var xx='sss'; } //do something if(condition){
I saw some old code that had: <input type=submit name=submit onsubmit=somefunction(this) /> I was
I saw some code on the apple website that goes like this id <NSFetchedResultsSectionInfo>

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.