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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:38:34+00:00 2026-06-14T06:38:34+00:00

I met a problem with nested_form gem. I have 5 models: Category, Group, Parameter,

  • 0

I met a problem with nested_form gem.
I have 5 models: Category, Group, Parameter, Offer and Value.
So Offers belongs to Category, Values belongs to Offers and Parameters, Parameters are united in Groups, and Groups belongs to Category.
Typical example is like

Category: car
  Group: engine parameters
    Parameter: volume
    Parameter: power
  Group: producer
    Parameter: producer_name
    Parameter: year
    Parameter: country

Category: bicycle
  Group: technical parameters
    Parameter: wheel diameter
    Parameter: weight
  Group: producer
    Parameter: producer_name
    Parameter: year
    Parameter: country

And values of this parameters belongs to offers. Maybe looks complicated, but it seems to me I illustrated it quite clearly.
I want to build form, which allows to create many Offers during user registration. Categories, parameters and groups are fixed.
Now my template is:

= simple_nested_form_for @user
  Category.all.each do |category|
    span= category.name
    = f.simple_fields_for :offers do |f_offer|
    = f_offer.input :category_id, :as => :hidden
    - category.groups.each do |group|
      span= group.name
      - if f_offer.object.values.where("parameter_id IN (?)", group.parameters).empty?
        - group.parameters.each do |parameter|
          - variant.values.build(:parameter_id => parameter.id)
      / In this partial inputs for offer values in format parameter_name: input_field
      = render :partial => 'values', :locals => { :f_offer => f_offer,
          :f_group => group }
    = f_variant.link_to_remove t("views.remove_variant")
  = f.link_to_add "Add offer", :offers

It works almost fine, but the problem is when I click “Add offer” link – form is added with parameters of last category.
So with examples I’ve given above, when I click “Add offer” for Car category – I see bunch of parameters not for car, but for bicycle! Looks like I should pass category to simple_fields_for or something like that, but I don’t have any idea how to do it.
Can anyone help me?

  • 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-14T06:38:36+00:00Added an answer on June 14, 2026 at 6:38 am

    I found a workaround for this problem: I’ve added a new action like “generate_form”, where I create new User and add new Offer to it, and in view I generate form for this new User with nested fields for it’s Offer.

    When user clicks “Add offer” link, I execute ajax request to this generate_form action, passing category id, but in response I get , so I cut nested form, with jQuery it’s quite easy, and also I need to replace zero offer id with randomly generated, both of these are performed by ajax “done” callback.

    Maybe quite ugly way, but finally it works.
    If anyone can provide another solution – I will be glad to see it.

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

Sidebar

Related Questions

I met strange problem. I have never work with Devise gem before. So, i
I met a problem with sum function: the data have a datetime column and
I have met some problem with jQuery ajax() in Safari, so I created some
Good day! I have met problem with synchronizing threads. I am writing program which
I met a problem like this. class A have a list of class B.
I have met a problem with virtualbox, I hope someone could help me here,
I have an implementation that just like gmail application, but have met some problem
I met a problem here, I have a cell like below. Two vectors and
I met a problem when Call to a member function combinestring() on a non-object.
I met a problem which is very strange, my company uses Visual Source Safe

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.