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
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.
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
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…
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.
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…
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.
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)
value|
record.errors.add(attr_name, configuration[:message]) unless
record.send("#{attr_name}_confirmation").nil? or value ==
record.send("#{attr_name}_confirmation")
end
end