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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:52:16+00:00 2026-05-26T06:52:16+00:00

Given following model: rails g model Menu name:string rails g model MenuHeader mh_name:string menu_id:integer

  • 0

Given following model:

rails g model Menu name:string
rails g model MenuHeader mh_name:string menu_id:integer

class Menu < ActiveRecord::Base
    has_many :menu_headers
    attr_accessible :menu_headers_attributes, :name
end

class MenuHeader < ActiveRecord::Base
    belongs_to :menu
end

Trying to add via rails console, I get:

Menu.create({"name"=>"My first menu",:menu_headers_attributes=>{:mh_name => "here is my name"}})
ActiveRecord::UnknownAttributeError: unknown attribute: menu_headers_attributes

What would be the correct syntax for adding this?

Could I remove the attr_accessible?

thx

edit #1 from bricker’s answer (thx btw, really appreciate!)

class Menu < ActiveRecord::Base
  has_many :menu_headers
  attr_accessible :name
  accepts_nested_attributes_for :menu_headers
end  

 ruby-1.9.2-p290 :001 > Menu.create({"name"=>"My first menu",:menu_headers_attributes=>{"mh_name" => "here is my name"}})
 TypeError: can't convert Symbol into Integer
from /Users/jt/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/nested_attributes.rb:395:in `[]'
from /Users/jt/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/nested_attributes.rb:395:in `block in assign_nested_attributes_for_collection_association'
from /Users/jt/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/nested_attributes.rb:395:in `map'
from /Users/jt/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/nested_attributes.rb:395:in `assign_nested_attributes_for_collection_association'
from /Users/jt/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/nested_attributes.rb:287:in `menu_headers_attributes='
from /Users/jt/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/base.rb:1745:in `block in assign_attributes'
  • 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-26T06:52:17+00:00Added an answer on May 26, 2026 at 6:52 am

    You need to add:

    accepts_nested_attributes_for :menu_headers
    

    into your Menu model. That will add the menu_headers_attributes as an attribute to Menu.

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

Sidebar

Related Questions

Given the following models, using rails 2.1: class Product < ActiveRecord::Base has_many :from_sources, :class_name
Given the following models: class Recipe < ActiveRecord::Base has_many :recipe_ingredients has_many :ingredients, :through =>
Given the following Model, public class A { public string Name { get; set;
I have the following model and methods: class UserPrice < ActiveRecord::Base attr_accessible :price, :purchase_date,
I'm using Rails 3. I have 3 models: class Deal < ActiveRecord::Base has_many :wishes,
I've got the following User model: class User < ActiveRecord::Base # Users table has
I have the following models with associations as given below:- class Comment < ActiveRecord::Base
Given the following model, I want to index the fields (sequence,stock) class QuoteModel(models.Model): quotedate
Given the following model: class Project(models.Model): project_name = models.CharField(max_length=255) abstract = models.TextField(blank=True, null=True) full_description
This is just an example, but given the following model: class Foo(models.model): bar =

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.