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

  • Home
  • SEARCH
  • 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 9066843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:48:29+00:00 2026-06-16T16:48:29+00:00

I have many models. Now I like to show the JavaScript to only the

  • 0

I have many models. Now I like to show the JavaScript to only the particular controller and method.

For example, if I had code like this and want to show it only in communities/show
Should I paste this in the head of view/communities/show.html.erb?
or is there smarter way to manage this kind of things?
Obviously it looks ugly if I put it in the head of show file because JavaScript always should be placed within < head> tag.

<%= javascript_tag do %>
    jQuery(document).ready(function () {
        refreshPartial();
        setInterval(refreshPartial, 5000)
    });


    function refreshPartial() {
      $.ajax({
        url: "<%= community_path %>/refresh_part",
        type: "GET",
        dataType: "script",
      });
    }
<% 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-06-16T16:48:31+00:00Added an answer on June 16, 2026 at 4:48 pm

    communities.js

    jQuery(document).ready(function () {
      refreshPartial();
      setInterval(refreshPartial, 5000)
    });
    
    
    function refreshPartial() {
      $.ajax({
        url: "community/refresh_part",
        type: "GET",
        dataType: "script",
      });
    }
    

    view/communities/show.html.erb

    <%- content_for(:head) do -%>
    <%= javascript_include_tag :communities.js -%>
    <%- end -%>
    

    communities_layout

    <head>
    <title>Merry Christmas!</title>
    <%= yield(:head) -%>
    </head>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a parent model that has many child models, for example: App.Blog =
I have many-to-many relationship between Game and Account models like below: class Account <
I have two models Customer and Transaction Customer has_many :transactions Transaction belongs_to :customer Now
In the Rails application I’m currently developing I have many request models. We are
I'm using rails 3.2. I have many to many type of models. Is there
I have models Product and Category . Category can have many products. ( Product
Given models User and Comments being populated such that a user may have many
I've got two models Category and Item. Category can have many items and item
I have 2 models that have a many-to-many association(an Event has many Products and
I have 2 models ( model1 and model2 ) that have a many to

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.