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.
Related
I've tested this by running rails c both before and after git stash. On Rails 4.1 in Mavericks, after following the instructions to add the versions table and adding has_paper_trail to three models, whenever I run rails c I get
irb: warn: can't alias context from irb_context.
I've spent some time Googling without much luck, there's old threads talking about rspec, but I don't see how that's relevant since I'm not using it. Any ideas why this is happening?
RSpec used to polute provide Object top-level methods, e.g. describe, context, etc. Fortunately they've got rid of all the monkey patching in version 3, and now all these methods are namespaced under RSpec.
One can change this behaviour through the expose_dsl_globally config flag. For backwards compatibility, it defaults to true.
The warning shows up when you open the console because paper_trail automatically loads its rspec helpers when rspec is found. And it calls RSpec.configure before you have the chance to tweak your own configuration.
One possible solution would be paper_trail to disable the automatically loading and let users to load it themselves when they see fit. However, I am not aware of the internals of the library, so I can't guarantee this wouldn't break other things.
Best!
This is now fixed in papertrail 4.0.0, here's the commit.
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.
I got these updates from rails:
I'd like to announce that 3.2.11, 3.1.10, 3.0.19, and 2.3.15 have been released. These releases contain two extremely critical security fixes so please update IMMEDIATELY.
link
as it says it's critical. I just updated my application with rails 3.1 to 3.11 and did bundle update rails. My questions are:
What was the actual loophole in rails that has now been fixed?
As a learner I'm eager to understand what the problem was and how has it been fixed. I couldn't get anywhere about this.
Is it really a big loophole, and is there any problem for all Rails application which haven't been updated?
Here's an explanation of the hack : http://charlie.bz/blog/rails-3.2.10-remote-code-execution
And the original post by tenderlove : https://groups.google.com/forum/?fromgroups=#!topic/rubyonrails-security/61bkgvnSGTQ
Basically, anyone can inject XML and instantiate any kind of Ruby object using YAML ... it's complicated, but works on all apps (except the patched one of course, and Rails 1.X) and can even execute system commands ...
Anyone having Rails apps around should already have upgraded ... if not, do it NOW!
I've got a Rails project that's setup using Bundler. One of my bundled gems provides a Rack middleware that I'd like to use in my Rails app (but only in the 'production' Rails environment).
If I just put something like this in config/environments/production.rb, I get an unknown constant error:
config.middleware.use ::Rack::MyMiddleware
... presumably because Bundler.require has not yet been called at this point, and none of my bundled gems are available.
I have found a few ways of working around this, but none seem great, and I'm wondering if there's a more standard solution that I'm missing:
Explicitly require 'my_middleware_gem' in config/environments/production.rb
Wrap the config.middleware.use call in an after_initialize block, ensuring that Bundler has a chance to do its thing before I try to reference the constant.
Use a string ("::Rack::MyMiddleware") instead of the bare class constant. This doesn't seem to work with Unicorn for some reason, but does work with some other servers (with Unicorn it ends up trying to call "::Rack::MyMiddleware".new, which of course fails).
Am I missing some better approach? At what point in the initialization process is it expected that bundled gems should be available?
Copying the answer from the comments in order to remove this question from the "Unanswered" filter:
matt suggested:
I think using the after_initialize block is the right way in this case.
grumbler confirmed:
Yeah, that's what I ended up going with. Thanks! Regarding the unicorn issue alluded to in the original question, turns out I was hitting this problem: http://davidvollbracht.com/blog/headachenewunicorn-capistrano-bundler-usr2
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?