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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:18:48+00:00 2026-05-26T14:18:48+00:00

I am in the process of prototyping a web application using ruby on rails.

  • 0

I am in the process of prototyping a web application using ruby on rails.

I’m a complete newbie to rails, but this question relevant to MVC programming in general.

In the past, when my model held some relevant information that needed to be accessible from my javascript files, I would have some inline javascript in my template and dump it to a global variable thusly:

<script type="text/javascript"> 
    var nodes=<%= @nodes.to_json.html_safe %>;
</script>

However, in production my plan is to use uglifier to compress my javascript files, my guess is that it will not know to rename the nodes variable in my erb files to be in sync with the minified javascript.

(I’m thinking storing it in a named hidden input might get around the minification problem, but feels even hackier…)

So my question is:

Can you suggest any more graceful alternatives to storing page state than dumping json objects in the global namespace?

Preferably in rails, but I’m also interested to see how people solve this problem in other mvc frameworks…

Thanks

  • 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-26T14:18:49+00:00Added an answer on May 26, 2026 at 2:18 pm

    Inline JavaScript is awful. That goes double when you’re creating JS values as strings. It creates maintainability problems and should be banished from your bag of tricks forever. JavaScript belongs in external JavaScript files, and those files should be static.

    What you want instead is something like:

    (view file)

    <div id="nodes"><%= @nodes.to_json %></div>
    

    (CSS)

    #nodes { display: none; }
    

    (JavaScript)

    var nodes = JSON.parse($('#nodes'))
    

    This is true regardless of your server-side language.

    Bonus Rails-specific tips: use Haml instead of ERb, and Sass instead of CSS. Much nicer.

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

Sidebar

Related Questions

My team is in the process of prototyping an application with a rather complex
I’m building a mobile web application, and even though I’m still in a prototyping
This process has been working fine in Chrome, but in Firefox 7.0.1 there are
There is a conversion process that is needed when migrating Visual Studio 2005 web
Process.Start(IExplore.exe); Does this always work, on every machine ? If not, how to do
I have an XSLT transform I am using to process an XML file, inserting
class Process implements Runnable{ private ThreadProcessing MIDlet; public Process(ThreadProcessing MIDlet){ this.MIDlet = MIDlet; System.out.println(Thread
I process some event, signaled by WFMO, and at this time it's signaled more
Using Process Explorer ( procexp.exe ), especially with Google Chrome, child processes are called
// Process the forms if (($this->getRequest()->isPost()) && ($this->getRequest()->isXmlHttpRequest())) { // Initiate response $status =

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.