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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:30:56+00:00 2026-06-14T10:30:56+00:00

Im building a report system which uses a sort of meta question model. Questions

  • 0

Im building a report system which uses a sort of meta question model. Questions are previusly saved in the database, and then depending of the type of report some questions are taken from the database.

Wanting to keep things DRY, i’m trying to figure out a way to pass the information of the Variable model to my report_header with no avail.

In the new action i have:

  reportBody = @report_head.report_bodies.build(:variable_id => a.id)
  @report_head.variables #modified, thx.

all i need is to pass the attributes from the Variable to report_head in a DRY way.

If you need to know my models:

class Variable < ActiveRecord::Base
  attr_accessible :id,:break_point, :description, :name, :time_frequency, :v_type
  has_many :report_bodies
  has_many :report_heads, :through => :report_bodies   
end

class ReportHead < ActiveRecord::Base
  attr_accessible :email, :name , :report_bodies_attributes, :report_bodies, :variables_attributes
  has_many :report_bodies
  has_many :variables, :through => :report_bodies   
  accepts_nested_attributes_for :report_bodies
end

class ReportBody < ActiveRecord::Base
  attr_accessible :report_head_id, :variable_value, :variable_id, :variables_attributes, :report_heads
  belongs_to :report_head
  belongs_to :variable
end

Update

I updated the model as suggested, and modified the way to call the variables. However im still confused about how to use it in the view, if i do something like:

   <%= f.fields_for :variables do |variable| %>
       <%= variable.text_field :name, :value => :name, :class => 'text_field' %>  
   <% end %>

it prints a string instead of the actual name.

  • 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-14T10:30:57+00:00Added an answer on June 14, 2026 at 10:30 am

    You have define wrong name association, your association of ReportBody should be:

    belongs_to :report_head 
    belongs_to :variable 
    

    This is not correct:

    @report_head.report_bodies.build(:variable_id => a.id,:report_head_id =>@report_head.id) 
    

    chang it to:

    @report_head.variables.build(:variable_id => a.id)
    

    it’s better, you don’t have to set report_head_id. And this is wrong:

    @report_head.report_bodies.variables
    

    If you want to get all variables belong to @report_head, you just need using:

    @report_head.variables
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a report using Report Builder 3.0. The source system I'm working with
I'm building a report for a database where I need to determine the number
I'm building a system which can create forms during runtime. System is written for
We are building an system which is B/S structure.And the customer want to print
I'm building this report in a system for a Billboard company. They have a
I'm building a report in Rally that finds all the defects which have been
I am building a report in SSRS. In design mode it looks like this:
I'm building a report in Visual Studio 2008 with a lot of multivalue parameters
I'm trying to join multiple tables together for building a report. The report lists
Building an inventory system. I have lots of products and each product has three

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.