i need help understanding this. If i'm reading it correctly, if i want
to add a has_many to the CE user.rb, i would do something like the
following in my user.rb file:
require_dependency "#{RAILS_ROOT}/vendor/plugins/community_engine/app/
models/user.rb"
class User < ActiveRecord::Base
has_many :myobject, :through => :user_myobject
end
this would allow me to keep all of the functionality in the CE
user.rb, but add my stuff. What about when i want to remove or change
functionality in the CE user.rb?
I'm trying to stay away from modifying the CE code, however, I'm not
sure it makes a difference whether i change it or override it. for
example, I've changed the shared/_admin_nav.html.haml partial to add
some new functionality. I did this by copy/pasting the view into my
project, then modifying it. This means that when CE has a new release,
and something is new in that file, I need to merge the diffs into my
new file. If that's the case, why not just modify the CE view, keeping
with the DRY idea.
based on the documentation for overriding the model, neither of the
two options there get around this. that assumes i understand them
completely too :-)
i hope this doesn't sound like to newbish of a question. I'm just
learning ruby / ror so bare with me.
thanks!
Levi
There are several of other ways to mix in your code into CE's models.
Taking User.rb as an example, you could:
1. Subclass the model, creating something like MyUser.rb in your
models directory.
2. Mix your code into User.rb, by writing a plugin or initializer
that adds your methods to the User.rb model dynamically (meta-
programming)
3. Other ways? (Suggestions welcome)
If you use the first method, you should check out the Rails
documentation for the 'becomes' method, which lets your switch objects
back and forth between classes. This is useful for taking the
current_user object (which is a User), and turning it into a MyUser
object.