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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:36:46+00:00 2026-06-04T06:36:46+00:00

My models I’m trying to create a form for an Annotation . This annotation

  • 0

My models

I’m trying to create a form for an Annotation. This annotation belongs to a Map, and each annotation should have one Boundary. A map can have many annotations.

I first created the association by letting both Annotation and Map has_one Boundary, but later I switched to using a polymorphic boundary_object. The error was the same regardless.

has_one :boundary, :as => :boundary_object         # <= Map
has_one :boundary, :as => :boundary_object         # <= Annotation
belongs_to :boundary_object, :polymorphic => true  # <= Boundary

Views and Controller

Here’s the thing: First I used Boundary.new to create a new boundary object here, since I didn’t have a pre-set annotation object, since the form can be submitted multiple times.

maps/show.html.erb

<%= form_for([@map, Annotation.new], :remote => true ) do |f| %>
    <%= f.text_area :body, :cols => 80, :rows => 10, :style => "width: 500px" %>
    <%= f.fields_for Boundary.new do |b| %>
      <%= b.text_field :ne_x, :style => "display:none" %>
      <%= b.text_field :ne_y, :style => "display:none" %>
      <%= b.text_field :sw_x, :style => "display:none" %>
      <%= b.text_field :sw_y, :style => "display:none" %>
    <% end %>
<% end %>

I could use f.fields_for :boundary too, if I have this in the maps_controller.rb:

@annotation = @map.annotations.build
@annotation.boundary = Boundary.new

But the result is still the same.

annotations_controller.rb

def create
  @annotation = Annotation.new(params[:annotation])
  respond_to do |format|
    if @annotation.save
      format.js { }
  end
end

The Error

When submitting that form, this results in the following error at the first line in the create method.

ActiveRecord::AssociationTypeMismatch (Boundary(#2158793660) expected, got ActiveSupport::HashWithIndifferentAccess(#2165684420))

Obviously, the form works without the whole boundary thing. These are the parameters submitted:

{
  "utf8"=>"✓",
  "authenticity_token"=>"6GDF6aDc6GMR3CMP+QzWKZW9IV9gSxfdkxipfg39q7U=",
  "annotation"=>
  {
    "body"=>"foo bar",
    "boundary"=>
    {
      "ne_x"=>"11312", 
      "ne_y"=>"5919", 
      "sw_x"=>"6176", 
      "sw_y"=>"1871"
    }
  }, 
 "map_id"=>"1"
}

What do I have to do to be able to create the Boundary object for this annotation right away?

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

    According to your associations:

    First, you need to build a new boundary object (see here for more info):

    def show
      @map = ...
      @annotation = @map.annotations.build
      @boundary = @annotation.build_boundary # build new boundary
    end
    

    Second, you need to edit your view:

    <%= form_for([@map, @annotation], :remote => true ) do |f| %>
      <%= f.text_area :body, :cols => 80, :rows => 10, :style => "width: 500px" %>
      <%= f.fields_for :boundary do |b| %>
        ...
      <% end %>
    <% end %>
    

    Third, check that you have accepts_nested_attributes_for for your Boundary in the Annotation model.

    accepts_nested_attributes_for :boundary
    

    The form will then look like this – note that the name of the association needs _attributes:

    <input … name="annotation[boundary_attributes][ne_x]" … />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

@models.map(&:attributes)) returns a list of hashes from each column to its value in the
3 models mapping 3 tables: Image, Slider and SliderImageAssoc. In this case it's one-to-many,
I have simple models with generic relations from this example at the Django Project
I have 3 django models (simplified for this example): class Fighter (models.Model): name =
Models relevant to this question: user, friend, interest, person_interest. Person_interest is polymoprhic and can
Are models available within the modules. Can I access constants stored in a model
Given models User and Comments being populated such that a user may have many
My models are set up as follows (this is an example and not my
My models produce a lot of values for attributes which the user can not
in models i have start and end date. How to get all element where

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.