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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:04:28+00:00 2026-05-14T15:04:28+00:00

I have a form with an ever-growing amount of associated javascript. At present this

  • 0

I have a form with an ever-growing amount of associated javascript. At present this javascript lives in my form view which is fine, but it’s getting larger and starting to overwhelm the form making it difficult to work on the form.

I want to put this in a separate file in my /public/javascripts directory but a lot of the javascript is generated by embedded ruby. This embedded ruby is ignored and passed through to the browser if I just put the code here.

What is the best way (if any) of having this embedded ruby executed and the javascript being generated in the same way as if it were in my view?

  • 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-14T15:04:29+00:00Added an answer on May 14, 2026 at 3:04 pm

    You can create dynamic erb templates for javascript, but they don’t go in the public/javascripts directory.

    I suggest you move the javascript into a partial.
    Create a file named _form_js.html.erb and put the content of your script tag there.
    Then <%= render :partial => ‘form_js’ %> from your view.

    As a side note, it is likely that you would be better off using completely static javascript that identifies elements of the form by their class/id and reacts to this, rather than using custom javascript for each element.

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

Sidebar

Related Questions

If I have a CSS class which I only ever apply to form elements,
I have a collection of the form: map<key, list<object> > I only ever insert
I have form in my page, I am using ajax.beginform(). Inside this form I
i have form with user data to input and javascript ajax to send information
I have form like this: <div class=satu> <input type='text' size='1' maxlength='1' name='score[1][]' id='score[1][]'> </div>
I have a form which contains listbox which will contains links of attachment when
I have a situation where I have a form with: a view popup1 (with
I have a micropost form which allows a user to upload a photo and
I have a form which one of it's fields is a code and description,
Almost all of the applications I've ever written have been GUIs of one form

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.