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

The Archive Base Latest Questions

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

attempting to use this railscast as a guide: http://railscasts.com/episodes/197-nested-model-form-part-2?view=asciicast and running into this error:

  • 0

attempting to use this railscast as a guide:
http://railscasts.com/episodes/197-nested-model-form-part-2?view=asciicast

and running into this error:

`@search[queries_attributes][new_queries][queries' is not allowed as an instance variable name

models:

#search.rb
class Search
  include Mongoid::Document
  include Mongoid::Timestamps


  belongs_to :user
  field :name,              :type => String

  embeds_many :queries
  accepts_nested_attributes_for :queries, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true

#query.rb
class Query
  include Mongoid::Document

  field :columns,           :type => String
  field :types,             :type => String
  field :keywords,          :type => String

  embedded_in :search, :inverse_of => :queries 

end

searches controller :

def new
  @search = Search.new
  @search.queries.build
  #3.times { @search.queries.build }
end

_form.html.haml partial:

= form_for(@search) do |f|
  = f.label 'Name this search'
  = f.text_field :name, :class => 'text_field'
  = render :partial => 'query', :collection => @search.queries, :locals => { :f => f }
  = link_to_add_fields "Add Query", f, :queries 

  .actions
    = f.submit

_query.html.haml partial:

.fields
  = f.fields_for "queries[]", query do |q|

    = q.label 'Search Datatype'
    = q.select :types, Query::TYPES

    = q.label 'In Column'
    = q.select :columns, @search.record_columns

    = q.label 'For Keywords:'
    = q.text_field :keywords, :class => 'text_field'

    = q.hidden_field :_destroy 
    = link_to_function "remove", "remove_fields(this)" 

searches helper:

module SearchesHelper

    def link_to_add_fields(name, f, association)
      new_object = f.object.class.reflect_on_association(association).klass.new
      fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
        render(association.to_s.singularize , :f => builder)
      end
      link_to_function(name, h("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")"))
    end

end

javascript:

function remove_fields(link) {
        $(link).prev("input[type=hidden]").val("1");
        $(link).closest(".fields").hide();
}

function add_fields(link, association, content) {
        var new_id = new Date().getTime();
        var regexp = new RegExp("new_" + association, "g");
        $(link).parent().before(content.replace(regexp, new_id));
}

when the line:

= link_to_add_fields "Add Query", f, :queries

is commented out, it works as expected, but I need to be able to add additional queries
via this helper.
for testing multi queries I am triggering the creation in the controller 3.times

also in the error message the last “]” is stripped off.. not sure what I am missing

sorry for all the tags, but not sure where the issue lies

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

    looks like this was the fix:

    = f.fields_for :queries, query do |q|
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I'm attempting to use this: http://blogs.msdn.com/b/priozersk/archive/2010/09/17/customizing-picker-box-dialog.aspx However, I just want a normal pickerboxdialog
Attempting to use the data series from this example no longer passes the JSONLint
I'm attempting to use code I've found that uses Win32. However, I'm getting this
I am attempting to use livequery. I unfortunately am stuck using jquery 1.2.6. This
I am attempting to compress a string via use of zlib (I've tried this
I'm attempting to use fluent html and the spark view engine in my asp.net
Ok, I am attempting to use this custom extension to perform an entity update.
I'm attempting to use this approach, described by Marco Arment, for checking if a
I am attempting to use this method I've constructed to save the layer of
I am attempting to use this code sample to control the Windows XP On-Screen

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.