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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:55:49+00:00 2026-06-10T18:55:49+00:00

I have this statement in application.html.erb: <%= yield(:javascript) %> and I have the following

  • 0

I have this statement in application.html.erb:

<%= yield(:javascript) %>

and I have the following Javascript, which should respond to the yield:

<% content_for : javascript do %>

  <script type="type/javascript">
    $(function() {
       call_to_function();
   });

  </script>

<% end %>

If I place the above block in home/index.html.erb, it works alright, but I want to somehow make it available to application.html.erb all the time, not just when I call home#index.

How can I achieve this, any pointers would be much appreciated?

  • 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-06-10T18:55:50+00:00Added an answer on June 10, 2026 at 6:55 pm

    Instead of using

     <%= yield(:javascript) %> 
    

    you can directly put your java script to application.html.erb in app/views/layout to share code throw out all the pages.

    There is no need to use yield when you have same contents through out. Yield is used when we have code specific to each page is different, from each page we call yield to actually replace the content of yield block.
    So, replace <%= yield(:javascript) %> by

     <script type="type/javascript">
    $(function() {
       call_to_function();
    });
    

    to appear in all your pages.

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

Sidebar

Related Questions

I currently have this statement in my SQL View (SQL Server 2008 R2) which
I have the following code: http://jsfiddle.net/SPWWx/ I'm completely new to javascript, this is my
In a JS file I have this: $.ajaxSetup({ type: 'POST', contentType: application/json; charset=utf-8, dataType:
I have this piece of code which calls a different NSLog statement depending on
I have the following statement in document.ready function: if($(sidebar ).html().trim().length == 0) { $(sidebar).append(<p>&nbsp;&nbsp;&nbsp;The
Let’s start with this statement: We have published couple of free applications on the
I have this statement in my c program and I want to optimize. By
We have this statement: (SELECT res_bev.bev_id, property_value.name AS priority FROM res_bev, bev_property, property_value WHERE
I have this SQL statement: SELECT * FROM history WHERE (fk_person = 2119) AND
I have this mysql statement: SELECT `review_userid` , `book_id` , `review_id` , `user_class` ,

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.