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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:27:13+00:00 2026-05-23T06:27:13+00:00

Just another Rails newbie with a problem. I have some Javascript (dynamic) in a

  • 0

Just another Rails newbie with a problem.
I have some Javascript (dynamic) in a partial .html.erb, but I have been informed in another post that this is really not where the Javascript should go. It’s dynamic so I can find the correct ID of an element and only apply the javascript on that particular element. I assume it is possible to parameterise the javascript and put it in an external file and somehow call it from my partial. Would that be the correct way to do it? If so how would I do that? If not what should I do?

I have a nested resource. On the parent resource’s show I am using AJAX to add children without leaving this page. I have quite a lot of Javascript magic that needs to be executed for each added child.

Partial _care_point.html.erb

<script>
  $(function() {
    $("#<%="node_#{care_point.id}" %>").live('dblclick', function(){
      console.log('moo');
      jQuery(this).hide();
      jQuery('.close', jQuery(this).parent()).show();
      jQuery('.node_input', jQuery(this).parent()).show();
    });
  });
</script>
<div id=<%="care_point.#{care_point.id}" %> class='draggable node_chin'>
  <div id=<%="node_#{care_point.id}" %> class='node'><%= care_point.body %>
  </div>
  <textarea class='node_input'><%= care_point.body %></textarea>
  <a class='close' href='#'>Close</a>
</div>

Thanks,

Erik

  • 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-23T06:27:14+00:00Added an answer on May 23, 2026 at 6:27 am

    In your partial:

    <div id=<%="care_point.#{care_point.id}" %> class='draggable node_chin care_point'>
      <div id=<%="node_#{care_point.id}" %> class='node'><%= care_point.body %>
      </div>
      <textarea class='node_input'><%= care_point.body %></textarea>
      <a class='close' href='#'>Close</a>
    </div>
    

    In public/javascripts/application.js (where your js should be)

    $(function() {
      $(".care_point").live('dblclick', function(){
        console.log('moo');
        jQuery(this).hide();
        jQuery('.close, .node_input', jQuery(this).parent()).show();
      });
    });
    

    Having used rails for a few years, I have never had to generate JS dynamically in the view. I can’t think of a good use case that would require this (if you can think of one, leave a comment please).

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

Sidebar

Related Questions

I have a Rails app where users can follow one another. I've just discovered
Rails gurus: I've just discovered named_scope thanks to another SO user. :) I'd like
This should be easy for many of you, but for me it's just another
I've just solved another *I-though-I-was-using-this-version-of-a-library-but-apparently-my-app-server-has-already-loaded-an-older-version-of-this-library-*issue (sigh). Does anybody know a good way to verify
Ok another WPF question, well I guess this is just general .NET. I have
In another question, Mark speaks highly of IDEs, saying some people still just dont
Rails newbie here. I have a list of items which can have a status
I have some trouble with using authlogic in my rails app, so I began
Another basic Rails question: I have a database table that needs to contain references
I have AS (as a plugin) working in another app just fine (I dont

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.