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.

On Nov 6, 5:37 pm, bobics <[EMAIL PROTECTED]> wrote:
> Thanks Bruno,
>
> Unfortunately the nil:NilClass problem was still happening, so I spent
> a *bunch* of time investigating the problem yesterday.  It turns out
> using "require" in general is a very bad idea except for gems and core
> ruby libraries.  The two symptoms I was seeing was A) the nil:NilClass
> error on production and B) the error "Help: A copy of <SomeClass> has
> been removed from the module tree but is still active!".  Originally I
> had thought these two problems to be unrelated, since the first
> happened on production, and the latter in dev mode.
>
> In my setup I used "require" to _extend_ the User controller in two
> places, and "require_dependency" to _override_ ther User controller in
> another.  When I changed everything to use "require_dependency"
> instead, both errors went away.
>
> This was a HUGE stumbling block for me, so hopefully by posting this
> on the CE group this will save someone else some time and suffering.
> Unfortunately, require_dependency is very poorly documented in RoR...
> even though this is what you should be using!  Reference below.
>
> -bobics
>
> http://spacevatican.org/2008/9/28/required-or-not
> per the article:
> "   * Just don't require stuff. If you lets Rails' automagic loading
> do its work none of this will happen
>     * If you do need to require stuff explicity, use
> require_dependency. This means that Rails is kept in the loop"
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CommunityEngine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/communityengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to