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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:02:13+00:00 2026-06-11T19:02:13+00:00

I followed Hartl’s Rails tutorial where he does Ajax using RJS and sending javascript

  • 0

I followed Hartl’s Rails tutorial where he does Ajax using RJS and sending javascript in the response to be executed on the client side to edit the DOM.

But what do you do if you want just JSON sent in the response and not send javascript. This also means the javascript to manipulate the DOM should already be in the html file on the client. Is there a tutorial as good as Hartl’s book on how to do this in Rails. Presumably it would use Jquery and some other stuff maybe that I’ve not heard of to make the code not be a million lines?

  • 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-11T19:02:15+00:00Added an answer on June 11, 2026 at 7:02 pm

    My best attempt at an answer is that it really depends on the scope and complexity of what you’re trying to achieve. Generally, JSON shows up in views. If your application does not require you to dynamically retrieve JSON, that is, you can load it all when the view is initially rendered, then you can set an instance variable in your view’s controller like so
    @my_json = some_object.to_json()
    Then, your instance variable is available in your view

        <script type = 'text/javascript'>
            var theJSON = <%= @my_json %>
        </script>
       

    Now, your data is available in the DOM, parsed nicely into JSON.

    If your application requires you to dynamically retrieve JSON after the controller/view are loaded, then you should probably look into using AJAX to hit a particular controller’s method that returns the JSON that you desire.

    Here’s a good RailsCast that can hopefully help you along your way Passing Data to Javascript

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

Sidebar

Related Questions

I followed a tutorial for sending email in Rails, and I have this in
I followed this video tutorial for detecting memory leaks using Instruments with Xcode 4.3.2.
I'm trying to learn to use Ruby on Rails (going through Hartl's tutorial for
Followed directions in Using JSLint in Notepad++ . Using JavaScript Lint (not JSLint). I
I followed this tutorial on configuring the Rails plugin ExceptionNotifier. I know that I
I followed a great tutorial ( http://iphone.zcentric.com/2008/08/28/using-a-uiimagepickercontroller/ ) on using a UIImagePickerController to get
I'm following Michael Hartl's amazing Rails Tutorial, but am wondering if there is a
I am new to Rails and finished Michael Hartl's Ruby on Rails 3 Tutorial.
I'm working through the Rails Tutorial, by Michael Hartl, and a question popped up,
I followed this tutorial . But whenever I try to log in with my

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.