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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:30:12+00:00 2026-06-15T08:30:12+00:00

does anybody know the difference between the object on the initial show.html.erb in Rails

  • 0

does anybody know the difference between the object on the initial show.html.erb in Rails and the index.html.erb? The reason I’m asking is because I’m using the javascript library d3.js and for that I need a json-object. In all index.html.erb I can create them with calling:
<% @commits.to_json %> but if I try to use that statement in any show.html.erb the browser tells me that the result is just an object (seems not to be a json) so that I later can’t call forEach (that I need to call).

Thanks in advance!

Ok, for a better understanding I append more code:

<%= javascript_tag do %>

d3.json('<% @commit.jobs.to_json %>', 
            function(data){


      var margin = {top: 20, right: 80, bottom: 30, left: 50},
          width = 960 - margin.left - margin.right,
          height = 500 - margin.top - margin.bottom;

      var format = d3.time.format("%Y-%m-%dT%H:%M:%SZ");

      //parse time format correct
      data.forEach(function(d) {
          console.log(d.finished_at);
          d.finished_at = format.parse(d.finished_at);
          console.log(d.finished_at);
        });

   //more code!     


<% end %>

The problem is, I have a commit object in show.html.erb that has belonging jobs and now I want to visualize the belonging jobs with d3.js. I tested if this: @commit.jobs.to_json creates a valid json and it does! But the console throws an error: Uncaught TypeError: Object #<Object> has no method 'forEach'

What am I doing wrong?

  • 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-15T08:30:13+00:00Added an answer on June 15, 2026 at 8:30 am

    In show you usually have only one @commit that you are showing.

    In index you usually have all @commits as an array of objects.

    def index
       @commits = Commit.all # all
    end
    
    def show
       @commit = Commit.find(params[:id]) # only one
    end
    

    if you want all commits in the show.html.erb do <%= Commit.all.to_json %>

    So there are technically no differences between the objects based on the view they are in. They just mean different (@commit,@commits) things based on how they got initialized in the method before calling the view.

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

Sidebar

Related Questions

Does anybody know what's the difference between Html.RenderAction and Html.Action ?
Does anybody know the difference between Using Index and Using where; Using index in
Does anybody know the difference between these two commands to switch and track a
Does anybody know the difference between GL_UNSIGNED_SHORT_4_4_4_4 and GL_UNSIGNED_SHORT_5_6_5 data types in OpenGL ES?
I need to find the difference between two PDF files. Does anybody know of
Does anybody know the memory difference between these two? Or how one would figure
Does anybody know what the main difference between session.commit() and session.flush() in SQLAlchemy is?
Does anybody know about differences in the drag-and-drop behavior between JDK1.6 and JDK1.7 ?
Does anybody know why this function, when passed an invalid date (e.g. timestamp) to
Does anybody know if the CUDA library 'Thrust' can generate random numbers on the

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.