Skip to content

Instantly share code, notes, and snippets.

@johnmcaliley
Created July 12, 2012 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmcaliley/3095339 to your computer and use it in GitHub Desktop.
Save johnmcaliley/3095339 to your computer and use it in GitHub Desktop.
Reopen rails engine model in app
# Rails 3.2.6
# my_engine/app/models/user.rb
# Define class in engine
class User < ActiveRecord::Base
#methods here
end
# my_rails_app/app/models/user.rb
# Require the engine model first and then reopen it to add new methods, associations, etc
require MyEngine::Engine.root.join('app', 'models', 'user')
class User
#new methods here
end
@westonplatter
Copy link

Rather than reopen the classes, I think I am going to implore this strategy.
https://gist.github.com/3132025

From your time with Rails Engines, will this cause problems in the long run?

The advice I have gotten so far says no.
https://groups.google.com/forum/?fromgroups#!topic/rubyonrails-core/jy2dQ0BQhnM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment