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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:25:28+00:00 2026-05-15T19:25:28+00:00

I have everything on my polymorphic associations working, but if I have model validations,

  • 0

I have everything on my polymorphic associations working, but if I have model validations, the erros don’t show up.

In my controller I have:

def create
    @locatable = find_locatable
    @geographic_location = @locatable.geographic_locations.build(params[:geographic_location])



    if @geographic_location.save
      flash[:notice] = t('migos.controller.geo_location_saved')
      redirect_to([@locatable, :geographic_locations])
    else
      flash[:error] = t('migos.controller.geo_location_error')
      render :action => 'new'
    end
  end

And in the Model:

class GeographicLocation < ActiveRecord::Base

  belongs_to :locatable, :polymorphic => true

  validates_presence_of :city, :message => "Falta Cidade"
  validates_presence_of :location

class User < ActiveRecord::Base
 has_many :geographic_locations, :as => :locatable

Very standard stuff. But the fact is, when the render :action => ‘edit’ happens, it goes to the right page, but the errors don’t show up.

My new.html.erb view:

<% semantic_form_for [@locatable, GeographicLocation.new] do |f| %>
    <% f.inputs :id => "geo_location" do %>
        <%= f.input :street, :label =>"Rua" %>
                <%= f.input :location, :label =>"Localidade" %>
        <%= f.input :city, :label =>"Cidade" %>
          <div class="clear geo"></div>
                <%= f.input :zipcode, :label =>"Código Postal" %>
                <%= f.input :zipextension, :label => "Ext." %>
          <div class="clear geo"></div>
                <%#= f.input :is_active_location %>
                <%=f.hidden_field :latitude%>
                <%=f.hidden_field :longitude%>
                <%= f.input :country, :as => :string, :label => "País", :input_html => {:default => "Portugal"} %>

    <% end -%>

  <%  f.buttons do %>
    <input id="map_center" type='button' onclick='getResults();' value='Centrar na morada' />
    <%= f.commit_button "Enviar"%>
    <h1><%= link_to "Cancelar", :back %></h1>
  <%end%>

My console output:

Processing GeographicLocationsController#create (for 127.0.0.1 at 2010-07-08 17:37:01) [POST]
  Parameters: {"commit"=>"Enviar", "action"=>"create", "authenticity_token"=>"z6gWF87u5hytrtXXsFAHKVl6fag3L3YmBKsfXcLqyKI=", "user_id"=>"72", "controller"=>"geographic_locations", "geographic_location"=>{"city"=>"", "latitude"=>"", "location"=>"", "country"=>"Portugal", "zipcode"=>"", "street"=>"", "longitude"=>"", "zipextension"=>""}}
  [4;36;1mUser Load (20.8ms)[0m   [0;1mSELECT * FROM "users" WHERE ("users"."persistence_token" = '4c46dcae34068fdb3bcf411a2f9498ad964137f3e9b6e4b9cfb9a64832b8bcefd9c406d8b0a678af93f9159dc59d4931a7ea404c67c744aad60cfb542c0ffbe1') LIMIT 1[0m
  [4;35;1mUser Load (0.4ms)[0m   [0mSELECT * FROM "users" WHERE ("users"."id" = 72) [0m
  [4;36;1mRole Load (0.4ms)[0m   [0;1mSELECT "roles".* FROM "roles" INNER JOIN "assignments" ON "roles".id = "assignments".role_id WHERE (("assignments".user_id = 72)) [0m
  [4;35;1mRole Load (0.2ms)[0m   [0mSELECT * FROM "roles" WHERE ("roles"."name" = 'admin') LIMIT 1[0m
Rendering template within layouts/application
Rendering geographic_locations/new
  • 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-15T19:25:29+00:00Added an answer on May 15, 2026 at 7:25 pm

    The problem is that you’re passing in a newly instantiated GeographicLocation every time you render the form. You should use the instance of the location you made in the controller and update via edit on submit, like the following:

    <% semantic_form_for [@locatable, @geographic_location] do |f| %>
    

    and do the following in your new action:

    @locatable = find_locatable
    @geographic_location = @locatable.geographic_locations.build(params[:geographic_location])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a strange one, I have everything working but in the controller code
I have wrote a custom MultipleChoiceField. I have everything working ok but when I
I have everything working from the tutorial, replacing it with my data, but it
I'm using phonegap to create mobile app. I don't want to have everything in
I'm trying to create an RMA form and I have everything working except the
I have everything installed. But when I run rake db:create, I get the following:
I have everything working locally with php_value include_path C:/wamp/www/project in my htaccess file, but
I feel like I have everything I need in my routes.rb, my controller, and
I am currently implementing a ListView populated with CheckedTextViews and have everything working just
people. I have slight problem with GD2 text on image. I have everything working

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.