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

  • Home
  • SEARCH
  • 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 8445161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:35:26+00:00 2026-06-10T09:35:26+00:00

I have a polymorphic model and want to have a nested form use this

  • 0

I have a polymorphic model and want to have a nested form use this model. I am getting no errors but the form is not displaying the nested field. Here are my models and stripped down form:

Polymorphic Model

class SeoMapping < ActiveRecord::Base
  belongs_to :mappingtable, :polymorphic => true
  attr_accessible :seo_url
  validates :seo_url, :presence => true, :uniqueness => true   
end

Page model using the Polymorphic Model

class Page < ActiveRecord::Base
  has_one :seo_mappings, :as => :mappingtable, :dependent => :destroy
  accepts_nested_attributes_for :seo_mappings 
  attr_accessible :content, :h1, :meta_description, :title, :seo_mappings_attributes
  .........
end

Now stripped down form

<%= form_for(@page) do |f| %>
  <% if @page.errors.any? %>
    .......
  <% end %>

  <div class="field">
    <%= f.fields_for :seo_mappings do |builder| %>
      <%= builder.label :seo_url %><br />
      <%= builder.text_field :seo_url %>
    <% end %>
  </div>

  <div class="field">
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </div>
  .........
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

I cant see why it does not display the fields_for elements. If I comment out accepts_nested_attributes_for the field then displays. Can you see where I am going wrong ?

TY

  • 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-10T09:35:27+00:00Added an answer on June 10, 2026 at 9:35 am

    Possibly a silly question but is this the create or edit action you’re talking about? And if it’s create, did you call @page.build_seo_mapping or something in the controller?

    Also (may be unrelated) if you use has_one, usually you want to use a singular noun, so has_one :seo_mapping instead of mappings.

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

Sidebar

Related Questions

I have polymorphic tagging model and I want to create tag_cloud for it, but
In my application I have a polymorphic Idea model. I want to use it
I have a tags model that I'd like to be polymorphic, but I don't
I have this pimpl design where the implementation classes are polymorphic but the interfaces
I have Rails polymorphic model and I want to apply different validations according to
I have a sign-up form that has nested associations/attributes whatever you want to call
How do I make a dynamic variable name/object? I have a polymorphic model for
I have Comment as a polymorphic model. It is attached to Post, Review, etc.
I have a model Articles that has_many Assets which is a polymorphic model that
I'm writing some tricky polymorphic relationships to handle tagging. I have a Tag model,

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.