Monday, March 3, 2008

Expected User, got User; forcing to reload plugins

I made my own plugin and started getting this error. This plugin is a variation of the acts_as_voteable plugin by Juixe. I did some searching around, I found this blog post that explains the fix.

Apparently, in development mode, there are issues when it comes to reloading plugins. Because the model "Vote" in my case, or "Comment" in the blog post's case, is defined inside the plugin, Rails doesn't see that it should load it again. Anyway, better to read that post for an explanation.

What I did to fix it was add this code at the end of the environment.rb file:
 # Array of plugins with Application model dependencies.
reloadable_plugins = ["acts_as_commentable"]

# Force these plugins to reload, avoiding stale object references.
reloadable_plugins.each do |plugin_name|
reloadable_path = RAILS_ROOT + "/vendor/plugins/#{plugin_name}/lib"
Dependencies.load_once_paths.delete(reloadable_path)
end
See the code.

1 comment:

Anonymous said...

Excellent - just what I needed for my own rails development today. This is a lot better than killing brick and restarting it over and over!

Thx.