I am experiencing a loop within a after_validation when trying to update
some attributes. Looks like it is calling validation recursively again
and again and I am getting "stack level too deep" error message. I
tried
using a skip_callbacks but with no success.
Why is this occurring and how to fix it?
require 'correios-cep'
class Address < ActiveRecord::Base
attr_accessible :id, :street, :neighborhood, :city, :state, :zipcode,
:country, :is_primary, :user_id, :latitude, :longitude,
:is_accurate_points
attr_accessor :invalid_primary, :populated_address, :skip_callbacks
belongs_to :user
validates :street, presence: true
validates :city, presence: true
#validates :neighborhood, presence: true
validates :state, presence: true
validates :zipcode, presence: true
validates :country, presence: true
validates :is_primary, :inclusion => {:in => [true, false]}
validate :is_primary, :invalid_primary?
validate :street, :validateStreet?
validate :zipcode, :validateZip?
after_validation :populate_address
def populate_address
self.neighborhood = populate_address.neighborhood
self.city = populate_address.city
self.street = populate_address.street
self.state = populate_address.state
end
end
Application Trace | Framework Trace | Full Trace
Request
Parameters:
{"utf8"=>"✓",
"_method"=>"patch",
"authenticity_token"=>"moURPhSZblDM6t70lg59TWUuDS8k6K/ygf8zMY1UBjE=",
"address"=>{"zipcode"=>"88025-100",
"street"=>"Rua Allan Kardec 35",
"neighborhood"=>"Agronômica",
"city"=>"Florianópolis",
"state"=>"SC",
"is_primary"=>"true"},
"commit"=>"Atualizar",
"id"=>"2"}
Toggle session dump
Toggle env dump
Response
Headers:
None
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/9abe5d35053dc8b0673039eaff02f4c1%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.