On Jun 18, 2014, at 2:09 PM, Walter Lee Davis wrote:

> 
> On Jun 18, 2014, at 2:03 PM, Rodrigo Lueneberg wrote:
> 
>> 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
> 
> If your method is called populate_address, and you have populate_address on 
> the second line of that method, what exactly do you expect to happen but a 
> loop? Is that a typo? You've used it over and over, and it doesn't seem to be 
> defined anywhere else.

1.9.3-p484 :001 > def foo
1.9.3-p484 :002?>   foo.bar
1.9.3-p484 :003?>   end
 => nil 
1.9.3-p484 :004 > foo
SystemStackError: stack level too deep
        from 
/Volumes/eddy/Users/waltd/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/irb/workspace.rb:80

> 
> Walter
> 
>> 
>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> 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.
> 
> -- 
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/C29B8A71-E86B-487A-8175-5C50313C0FA4%40wdstudio.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/70A8F0AF-20C5-4099-9D0D-9C5A8A490ED3%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to