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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:39:59+00:00 2026-06-02T18:39:59+00:00

I’m building a web application that needs a somewhat complex form to function. I

  • 0

I’m building a web application that needs a somewhat complex form to function.

I have five models: Grid, Row, Value, VariableGroup and Variable (these are not the actual names but useful for reference).

A Grid has many rows, and a Row has many values. Also, a Grid belongs to a VariableGroup, which is a sort of a model that groups many variables for their grandchildren.

A Variable, of course, belongs to a VariableGroup, and the key here, is that a Value belongs to a Variable as well.

The models:

class Grid < ActiveRecord::Base
  belongs_to :variable_group
  has_many :rows
  accepts_nested_attributes_for :rows, :allow_destroy => true
end

class Row < ActiveRecord::Base
  belongs_to :grid
  has_many :values
  accepts_nested_attributes_for :values, :allow_destroy => true
end

class Value < ActiveRecord::Base
  belongs_to :variable
  belongs_to :row
end

class Variable < ActiveRecord::Base
  belongs_to :variable_group
end

class VariableGroup < ActiveRecord::Base
  has_many :variables
  has_many :grids
end

The expected behavior is as follows to create a new Grid:

The user must select a VariableGroup from a dropdown select. This select has a jQuery handler for .change, that must instantiate a nested Row model, which in turn instantiates as many Value models as Variables exist in the Grid’s selected VariableGroup.

This is the grid form:

= simple_form_for @grid, :html => {:class => 'form-horizontal' } do |f|
    = f.input :name
    = f.association :variable_group_id
    .rows_and_values_container
      = f.simple_fields_for :rows do |p|
        = render 'rows_fields', :f => p
    = f.submit

And this is the attached listener:

$('document').ready(function(){
    $('#grid_variable_group_id').change(function(){
        $.ajax({url: '/grids/load_variables_in_values',
        data: 'selected=' + this.value,
        dataType: 'script'})        
    });
});

And this is the load_variables_in_values action:

def load_variables_in_values 
    @grid = Grid.new
    row = @grid.rows.build
    
    @variables = Variable.where(:variable_group_id => params["selected"])
    @variables.each do |variable|
        value = row.values.build
        value.variable_id = variable.id
    end
    # render :partial => "test_data_sets_fields"
    respond_to do |format|
      format.js
    end
end

The respond_to block yields the control to a js.erb view that should load the following partial, but I’m stuck here as I don’t know where and how to handle the loading of the partial and its sub-partials:

#rows_fields partial
= f.input :name
    = f.input :grid_id #Should be hidden
    = f.simple_fields_for :test_data_values do |p|
        = render 'values_fields', :f => p

#values_fields partial
= f.input :value
= f.input :row_id #Should be hidden
= f.input :variable_id #Auto-assigned

I think I’m 80% there, but I don’t know how to load the partials with its corresponding values with the data that I process in the custom controller action that was called via AJAX.

I know this is a mile long post, so thanks in advance if you got ºhere.

  • 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-02T18:40:00+00:00Added an answer on June 2, 2026 at 6:40 pm

    Rendering a partial from the custom controller action instead of using a respond_to block worked.

    I just had to hard-code the scope of the form (reading the source of the auto generated form and using its structure as a string, together with a random value, and it worked.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.