Monkey-Patching User in ChiliProject
Here is how to patch the User
model within a ChiliProject plugin.
What’s the deal?
When ever you try to patch the User
model you will see weird errors like
Expected user.rb to define User
and such. Sometimes it is even more subtile.
The cause is often, that the tight dependecies between the User
, Principal
and Project
models are not loaded properly - most often caused by a plugin
which uses require_dependency
to load one of them.
And the fix:
I was running into this problem multiple times and I wanted to note - once and for all - you will need the following statements to make it work:
require_dependency 'project'
require_dependency 'principal'
require_dependency 'user'
Then everything should be good to go.
See it in action
At the moment, you may see this in action
in the Safe Password Hashes for ChiliProject
plugin. Have a
closer look at the
user_patch.rb
.

My name is Gregor Schmidt. I am a freelance Ruby and JavaScript web developer based in Berlin, Germany. I do Ruby and Rails since 2005, JavaScript since 2006. I wrote my first Redmine plugin in 2007.
I mainly work with Rails, Backbone, and Bootstrap, but I am also good at picking up new frameworks, since I will probably know most of their concepts from other projects.
If your interested in more of my previous work have a look at my portfolio. I have also published my rates for everybody to see. I would love to hear, how I may help you.