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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:48:43+00:00 2026-06-12T02:48:43+00:00

Background and my research I would like to send data from server to client

  • 0

Background and my research

I would like to send data from server to client without reloading the page on the browser. I was reading Rails guide and using JSON seemed promising. (Correct me if I am wrong).

2.2.8 Rendering JSON

JSON is a JavaScript data format used by many AJAX libraries. Rails
has built-in support for converting objects to JSON and rendering that
JSON back to the browser:

render :json => @product You don’t need to call to_json on the object
that you want to render. If you use the :json option, render will
automatically call to_json for you.


Problem

I want to be able to render this JSON object back in the browser side. The following are appropriate code for the problem.

VideosController

class VideosController < ApplicationController
  include VideosHelper

  def home
    @video = Video.last
  end

  def next
    @next_video = next_video(params[:id])
    render :json => @next_video
  end
end

next.json.erb

{
  "title": "<%= @video.title %>"
  "url": "<%= @video.url %>"
  "youtube_id": "<%= @video.youtube_id %>"
  "genre": "<%= @video.genre %>"
  "category": "<%= @video.category %>"
  "likes": "<%= @video.likes %>"
  "dislikes": "<%= @video.dislikes %>"
  "views": "<%= @video.views %>"
  "user_id": "<%= @video.user_id %>"
  "created_at": "<%= @video.created_at %>"
  "updated_at": "<%= @video.updated_at %>"
}

If I want to render @next_video JSON object on home action. How do I do this?

  • 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-12T02:48:44+00:00Added an answer on June 12, 2026 at 2:48 am

    You need some js handler i guess. Something like that in home.html.erb:

    $.ajax({
      url: '<%= next_video_path(@video.id) %>',
      type: "GET",
      dataType: "json",
      success: function(data) {
        // something brilliant here 
      }
    })
    

    also in next.json.erb you should change @video to @next_video(since you don’t have @video initialized in next action). Also one more suggestion – you can use REST those renaming next to show and deleting home(since you can replace it with show now) and you will need to change previous code to:

    $.ajax({
      url: '<%= video_path(@video.next) %>',
      type: "GET",
      dataType: "json",
      success: function(data) {
        // something brilliant here 
      }
    })
    

    Where @video.next will return id of the next video.

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

Sidebar

Related Questions

Background I'm designing a Rails app to record research data. Most of it can
Background : I've inherited some MATLAB code to analyze data for my Ph.D. research.
Background: I would like to dismiss a modalView that I have presented earlier and
Background: Using unix, codeigniter from localhost. I'd like to run a controllers via a
Some background information The files I would like to download is kept at the
Background: We're building an application that allows our customers to supply data in a
Background: I'm doing machine learning research, and want to use the FANN library to
[background below] I've got my data modelled out in SQLObject in Python on the
I would like to know the OpenGL Rendering settings for having a program render
Background: I'm working on a single page web app that loads everything through AJAX

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.