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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:11:06+00:00 2026-05-16T11:11:06+00:00

I have called a function from a class to find all the items related

  • 0

I have called a function from a class to find all the items related to a particular ID in a many to many HABTM relationship.

Procedures -> Tasks with a join table: procedures_tasks

I call the information like @example = Procedure.get_tasks(1,1)

I would like to be able to iterate through the data returned so that I can create an instance of each task_id related to the procedure in question

  def self.get_tasks(model_id, operating_system_id)
    find(:first,  :select => 'tasks.id, procedures.id', :conditions => ["model_id = ? AND operating_system_id = ?", model_id, operating_system_id], :include => [:tasks])
  end

I tried rendering the data as i normally would and then using .each do |f| in the view layer, but i get:

undefined method `each' for #<Procedure:0x2b879be1db30>

Original Question:

I am creating a rails application to track processes we perform. When a new instance of a process is created I want to automatically create rows for all the tasks that will need to be performed.
tables:

  • decommissions
  • models
  • operating_systems
  • procedures
  • tasks
  • procedures_tasks
  • host_tasks

procedures -> tasks is many to many through the procedures_tasks join table.

when you start a new decommissioning process you specify a model and OS, the model and OS specify which procedure you follow, each procedure has a list of tasks available in the join table. I am wanting to create a entry in host_tasks for each task relevant to the procedure relevant to the decommission being created.

I’ve done my head in over this for days, any suggestions?

class Procedure < ActiveRecord::Base
  has_and_belongs_to_many :tasks
 #has_many :tasks, :through => :procedures_tasks
# has_many :procedures_tasks
  belongs_to :model
  belongs_to :operating_system
  validates_presence_of :name
  validates_presence_of :operating_system_id
  validates_presence_of :model_id

  def self.get_tasks(model_id, operating_system_id)
    find(:first,  :select => 'tasks.id, procedures.id', :conditions => ["model_id = ? AND operating_system_id = ?", model_id, operating_system_id], :include => [:tasks])
  end

end

the get_tasks method will retrieve the tasks associated with the procedure, but I don’t know how to manipulate the data pulled from the database in rails, I haven’t been able to access the attributes of the returned object through the controller because they haven’t been rendered yet?

ideally i would like to be able to format this data so that I only have an array of the task_id’s which i can then loop through creating new rows in the appropriate table.

  • 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-16T11:11:07+00:00Added an answer on May 16, 2026 at 11:11 am

    It wasn’t looping through because I was using the :first option when finding the data. I changed it to :all which allowed me to .each do |f| etc.

    Not the best option, but there will only ever be one option anyway, so it won’t cause a problem.

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

Sidebar

Ask A Question

Stats

  • Questions 531k
  • Answers 531k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think it depends on the context of your application.… May 16, 2026 at 11:53 pm
  • Editorial Team
    Editorial Team added an answer = NULL is always unknown (this is piece of 3… May 16, 2026 at 11:53 pm
  • Editorial Team
    Editorial Team added an answer They are part of the same ASP.NET application and therefore… May 16, 2026 at 11:53 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I want to have a collection of objects, which will be of a class
I have a very simple function which takes in a matching bitfield, a grid,
I didn't find much in tutorials on this specific question.. So I have a
First of all I have to admit that my programming skills are pretty limited
I have a website developed on Drupal. I use a module called collapsiblock (it
i have created below function in a file info.php to debug variable & data
Okay, I have a function which reads a xml file and creates controls using
I have a method that queues some work to be executed asynchronously. I'd like
Is there a way to debug a function that is defined dynamically in run
This is an annoying problem I am having with Twisted.web. Basically, I have a

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.