I recently upgraded from Rails 2.0.2 to 2.3.8 and have been ironing out the kinks. This one is baffling me.
I have a page that runs fine in production, but in development mode it runs fine on first load, then on reload it crashes with:
ActiveRecord::ConfigurationError - Association named 'average_prices' was not found; perhaps you misspelled it?
It's a nested eager-load call:
list_user.bookmarks.visible_to_user(logged_in_user_id).find(:all, :conditions=>filter, :include=>[:user, {:gift=>:average_prices}, :tags, :product_image])
My feeling is that the error isn't strictly related to the real problem... aside from the fact that the code runs correctly (in production) I have also observed other errors sporadically in my app to the effect of:
A copy of [one of my helper classes] has been removed from the module tree but is still active!
Googling for this has resulted in much discussion of marking classes as "unloaded" and using "require_dependency" instead of "require"... but I've tried a number of things without any luck.
Does anyone have any clues here? Something seems funky to me with regard to loading/reloading classes.
NOTE: I think what I'm seeing is likely the same as this, but the fix posted here didn't work for me.
I've had similar problems when I was using certain plugins. Could this come from a plugin?
Related
I am working through the Ruby on Rails Tutorial Sample app and I don't understand how I can fix the warning and the multiple tests that get run every time but don't do anything.
Screenshot of multiple tests running with the warning.
I am unsure if this is messing with performance or if it something I should just ignore, but I would like to resolve this issue if possible.
Thanks for the help, friends!
I've searched fairly extensively for any advice and have yet to find it so, here goes:
My Rails project fails to automatically reload models in development. Reloading them currently requires a full server restart.
Previous instances of this issue have been related to non-activerecord files placed in the models directory, though this is not the case for me.
config.cache_classes is properly set to false in my development config file. Views and controllers reload without issue.
All of my rails components are version 3.2.11. I have tried disabling all of my development-specific gems to no avail. This is obviously not a productivity stopper, but it is quite an annoyance. Any help appreciated and I am happy to provide more information if it would help, though I am not using any exotic gems.
Thanks!
Some possibilities:
You are not really running on developement environment
You are changing a model within a namespace and didn't told rails to autoload the path
You are changing a file that is included in your class, not your class directly (or any of the many variants for this)
You are caching classes
Considerations:
Things might change according to the webserver you are using
How do you know it's not reloading?
I ask my question because I was having the exact same issue when I was trying to insert a debugger into what I thought was a piece of code that was being executed. I assumed the model wasn't being reloaded since it was not hitting the debugger but it was actually a call back that was redirecting me around the code with the debugger line in it.
So, it might be something other than your models not being reloaded.
UPDATE: this problem was simply due to the app having an existing class called StateMachine... see the answers section.
Hi,
I'm having an irritating problem: after adding state_machine to my bundle for a Rails 2.3.11 app, something breaks.
Symptoms:
vendor/plugins seem not to be loaded - acts_as_paranoid and acts_as_lists at least, resulting in "undefined method 'acts_as_paranoid" etc.
removing those plugins, trying to narrow in on the problem, i get
"undefined method 'state_machine'", indicating that the state_machine gem is not loaded either, even though it's defined in the bundle (yes, i've run 'bundle install' and verified that it got in)
This hints me that something is breaking in the rails boot/loading of gems and plugins, and that the state_machine gem might cause this. I've tried with almost all versions of state_machine from 0.7.0 to 1.0.0
My question: Where to look for information to hint me of what's wrong?
I know little of debugging Rails during loadtime - so any directions is welcome :-)
The problem was apparently due to a naming conflict, since the app already had an observer class called StateMachine.
class StateMachine < ActiveRecord::Observer
observe :modelname
...
So - stupid me, should have known.
I resolved by building a separate app, adding stuff little at a time, until stumbling over the 'violating' code by accident. Still it feels like attacking the issue in a structured manner was the right way forward.
I could have used more knowledge on load time life cycle and debugging though.
I am trying to solve a strange issue with ferret/acts_as_ferret
Of course I have googled and posted the question:
http://www.ruby-forum.com/topic/188570
Basically aaf works on single models with no issue. It also works on single models using the config/aaf.rb file I have setup. It even works when I do a multi-model search in the console, but within the rails app itself I get:
undefined method `ferret_rank=' for <object that has a match>
If anyone has had the same experience/problem and can shed any light I would appreciate it.
PS: I followed the following tutorial to get where I am now.
http://opensoul.org/2008/4/29/using-shared-indexes-with-acts_as_ferret
Do you have the plugin installed or just the gem? You might want to install the plugin.
I would also try rebuilding the index.
For my purposes, I switched to Solr and life is a lot easier. Sphinx is missing a lot of stuff that I need.
I'm having a weird problem, where tagging works fine on my development machine, but when I deploy to the production server, I get this error in the log:
ActionView::TemplateError (undefined method `tags' for #<Person:0x98bb9d4>) on line...
There is an entry in the production.log file that states that has_many_polymorphs is loaded, so it's not like the plugin isn't available on the production machine.
My Google-fu has failed me trying to find the answer, so if anyone knows what could be wrong it would be greatly appreciated!
Edit: I should have mentioned that on both production and development I'm using the same database. I downloaded the production one, and used it on the development machine and it works fine.
cap deploy:migrations
I've seen similar problems to this in which the polymorphic type field is not getting correctly filled in, or when there was some existing data prior to the polymorphic type tag getting added. Is person a subclass? does the _type field contain any null values on the polymorphs table?
Just stabbing in the dark here, but has_many_polymorphs doesn't natively add tagging functionality to your models. Instead, you use a generator to create a tagging extensions module that goes into lib/tagging_extensions.rb. The module file has helper methods that add tagging functions, built on top of the has_many_polymorphs base functionality.
So, is it possible that you have the plug-in installed, but not the tagging extensions file?
I spent some time with a consultant tracking this down, and eventually we discovered that for reasons unknown, the Tagging stuff just wasn't being loaded.
By adding a single line of code, just three letters, to the end of environment.rb, it was resolved. I commented it so that we'd never forget wtf was going on:
# Magic begins here.
# We need to force Rails to load the Tag record, or
# has_many_polymorphs doesn't work properly. I don't know
# if there's a better fix, but this one seems reasonable. :-/
Tag
That was it. I'm sure there's an elegant and proper solution to this, but this works. Weird.
I hope this helps someone out there.