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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:53:14+00:00 2026-06-02T13:53:14+00:00

Rails App. I have a Project and a Task Model. Tasks have a column

  • 0

Rails App. I have a Project and a Task Model. Tasks have a column project_id to set the project they belong to, and several completeness columns to indicate completeness of the task over the time (so I have a column ‘completeness_at_3hours’, ‘completeness_at_6hours’ etc), to indicate from 1 to 5 the level of completeness of the task.

I now need to graph, with google charts the completeness over the time of the tasks that belong to a project.

In my Projects controller I have

@tasks = Tasks.where("project_id = ?", params[:id])

So, now that I have the tasks of the selected project, in @tasks, how would I include the data in the google chart script?

function drawChart() {

        var data = google.visualization.arrayToDataTable([
          ['Time', '<%= @task.name %>', '????????'],
          ['<%= @task.created_at %>',  <%= @task.zerohours %>, '?????????'],
          ['<%= @task.created_at + 3.hours %>',  <%= @task.threehours %>, '????????'],
          ['<%= @task.created_at + 6.hours %>',  <%= @task.sixhours %>, '????????'],
          ['<%= @task.created_at + 9.hours %>',  <%= @task.ninehours %>, '????????'],
          ['<%= @task.created_at + 12.hours %>',  <%= @task.twelvehours %>, '????????']
        ]);

this works for only one task (the one that has just been created), but how do I pass to the script all the data contained in @tasks?

I mean, to retrieve the data in a simple table I would use:

<% @tasks.each do |task| %>
<%= @task.threehours %>
<%= @task.sixhours %>
<%= @task.ninehours %>
<%= @task.twelvehours %>
<% end %>

But how do I do the same thing but inside the google chart script?

Thanks a lot!!

  • 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-02T13:53:15+00:00Added an answer on June 2, 2026 at 1:53 pm

    As far as I can tell you want to pass additional tasks in place of question marks, right? If so, I have a solution. First you might want to wrap code in a function:

    var data = google.visualization.arrayToDataTable(<%= make_a_chart %>);
    

    and place it somewhere in a corresponding helper:

    def make_a_chart
      result = []
      result.push make_labels, 
                  make_data( 0, "zerohour" ), 
                  make_data( 3, "threehours" ),
                  make_data( 6, "sixhours" ),
                  make_data( 9, "ninehours" ),
                  make_data( 12, "twelvehours" )
      return result
    end
    
    def make_labels
      y = ["Time"]
      for task in Task.all do
        y.append task.name
      end
      return y
    end
    
    def make_data( time, completeness )
      y = Task.first.created_at + time
      for task in Task.all do
        y.append task[completeness]
      end
      return y
    end
    

    This code assumes that all tasks are started simultaneously and that your database is called “Task”. Also it’s most likely quite crude and can use some improvements.

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

Sidebar

Related Questions

In a Rails 3.2 app I have a model Project, which has many Tasks.
On my rails app I have a list of items (like a task list)
I have a Rails project that is basically a simple web app for a
I am creating a new rails app as a learning project. I have already
I have been given the unpleasant task of installing a Rails 3 app I
I have a simple rails app with models project and phase. A project has
In my rails app I have the following models: Messages (id, title, content, project_id)
In a Rails app I have Sales and Salespeople: class Sale < ActiveRecord::Base belongs_to
I am creating a rails app and have used this code in one of
I want to use mysql with a rails app (I have never used mysql

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.