Source not reloading on development env

for some days i have strange behavoir with my environment … the
following scenario:

  • dev env
  • mongrel
  • City model
  • autocomplete_city controller action

when i do changes to the city model i need to restart the server that
the changes have an effect… and then the first request with the
autocompleter works and the second not … it says that a method is
missing (a method ive added myself)

First thing that comes to mind is that your application isn’t completely
restarting. Do you have more than one back-end server? (mongrel)
Check to see that they’ve all restarted

On Nov 28, 2007 8:11 AM, Michal G. <

I’ve had this issue too - I believe there is a bug filed for it
already.
AFAIR the relations don’t get properly reloaded and the you get
methods missing of course - pretty annoying stuff.

yeah i have only one mongrel running …

@stefan: you had this issue too … why had? did you solve it ?
it seems that this is only the case on XHR…

does no one have any clue how i could solve this problem … it is very
annoying that after the first request the methods seem to be gone

I ran into this today. Short version: don’t require things if they’ll
be autoloaded.

Long version:
If you just write Customer, const_missing gets hit, which goes off to
the Dependencies stuff. This marks customer as a thing that was
autoloaded, and when the application is reset it know to unload the
Customer model.

if you require ‘customer’ none of this happens, and so customer is not
put on the list of autoloaded things, and it not reloaded.

Where it gets really bad is if for example customer has_one :order.
Customer is not reloaded, and so hangs on to the ‘old’ version of
order. This old version was cleared out as part of the reset, which
leads to mysterious method_missing errors

Fred

thanks frederick. so you reckon that i dont require something which is
being autoloaded… the funny thing is that i am not using require for
my classes … they are all autoloaded …

it’s very strange and i don’t know what to do … things get not
reloaded and properties which are added programmatically to active
record classes are not recognized after the first request was made…

On 29 Nov 2007, at 18:20, Michal G. wrote:

thanks frederick. so you reckon that i dont require something which is
being autoloaded… the funny thing is that i am not using require for
my classes … they are all autoloaded …

Well I’d double check and scan through everything. If you’ve got
models in plugins that can also be problematic (remove the plugin’s
lib path to Dependencies.load_once_paths if that happens). I forget
exactly how but you can also get the Dependencies system to log what
it’s up to.

Fred

very very strange. i have discovered the problem now but i dont know why
this causes the problem. maybe someone knows why … following setup:

USER MODEL:

include CustomValidationsHelper

class User < ActiveRecord::Base
:validates_confirmation_of :email
end

CUSTOMVALIDATIONHELPER excerpt

#holds some custom validations for the use within models
module CustomValidationsHelper

EMAIL_PATTERN =
/^[a-zA-Z][\w.-][a-zA-Z0-9_]@[a-zA-Z0-9][\w.-][a-zA-Z0-9].[a-zA-Z][a-zA-Z.]*[a-zA-Z]$/

#- allows only 0-9, a-z, A-Z, _.- and space
#- an empty string is also valid
WORD_PATTERN = /\A[ \w.-]*\Z/

#mainly because they allow to create fake email easily.
#in LOWERCASE!!!
DISALLOWED_EMAIL_HOSTS = %w(mailinator.com mailinator.org
mailinator.net)


end

when i now use the User in some controller and make a form for it i get
a ‘Undefined method email_confirmation=’ after posting the form more
than !!once!!.
When i now remove the constants within the CustomValidationsHelper then
everything works fine… thats so strange.

i’ve tried this within a complete clean/new rails app (to simulate the
scenario) and this happens … i would like to know why this happens.

would be cool if someone has the time to help me with this … its very
strange behavoir. frederick may if you have sometime to try the
scenario…

On Nov 29, 2007, at 10:39 PM, Michal G. wrote:

include CustomValidationsHelper

class User < ActiveRecord::Base
:validates_confirmation_of :email

That leading colon is a typo?

end

That top-level include is strange, you probably want to mixin the
module into User. But in any case a model that has an attribute to
confirm needs a virtual attribute_confirmation accessor to be seteable
and validable:

class User < AR::Base
attr_accessor :email_confirmation
validates_confirmation_of :email
end

Unless email_confirmation= is defined by some code you don’t show it
does not exist and Ruby rightly complains.

– fxn

That leading colon is a typo?

yeah sorry a typo…

module into User. But in any case a model that has an attribute to
confirm needs a virtual attribute_confirmation accessor to be seteable
and validable:

class User < AR::Base
attr_accessor :email_confirmation
validates_confirmation_of :email
end

Unless email_confirmation= is defined by some code you don’t show it
does not exist and Ruby rightly complains.

no no this is fine … if you use the validates_confirmation_of then the
attributes are added automatically … here is the source (rails already
adds it)

def validates_confirmation_of(*attr_names)
configuration = { :message =>
ActiveRecord::Errors.default_error_messages[:confirmation], :on => :save
}
configuration.update(attr_names.pop) if
attr_names.last.is_a?(Hash)

    attr_accessor *(attr_names.map { |n| "#{n}_confirmation" })

    validates_each(attr_names, configuration) do |record, attr_name, 

value|
record.errors.add(attr_name, configuration[:message]) unless
record.send("#{attr_name}_confirmation").nil? or value ==
record.send("#{attr_name}_confirmation")
end
end

On 29 Nov 2007, at 21:39, Michal G. wrote:

:validates_confirmation_of :email
end

I’d change that to

class User < ActiveRecord::Base
include CustomValidationsHelper

validates_confirmation_of :email
end

Including the module at the top level probably does odd things to the
autoloading stuff.

Fred

Frederick C. wrote:

On 29 Nov 2007, at 21:39, Michal G. wrote:

:validates_confirmation_of :email
end

I’d change that to

class User < ActiveRecord::Base
include CustomValidationsHelper

validates_confirmation_of :email
end

yep that works fine …

Including the module at the top level probably does odd things to the
autoloading stuff.

Fred

thanks guys supporting me with this problem … it was not easy to find
this bit.

On Nov 30, 2007, at 2:21 AM, Michal G. wrote:

no no this is fine … if you use the validates_confirmation_of then
the
attributes are added automatically … here is the source (rails
already
adds it)

Oh yes you are right.

The Agile uses those explicit attr_accessors, but I see there’s a
patch to make the docs clear about this:

http://dev.rubyonrails.org/ticket/8815

– fxn