Rails Engines - simple possible engine to (1) add a model and (2) add the association in the containing class -
i trying write first engine having problems following scenario. in host app, have user model (this guaranteed in engine can refer user class rather level of indirection) has name. in engine, have post model , need create association between post model , user model in containing app.
>rails plugin new abc --mountable ... >rails g model post header:string body:text user_id:integer
... edit post file:
module abc class post < activerecord::base attr_accessible :body, :header, :user_id belongs_to :user def self.say_hello puts "hello: " + object.const_get(user).to_s end end end
how access user model in containining class add following?
has_many :abc_posts, class: "abc::post"
i have tried every variation of having in engine (at app/models/ app/models/abc etc....):
class user < activerecord::base has_many :abc_posts, class: "abc::post" end
but no avail. how work?
thx in advance
Comments
Post a Comment