0

I am writing a plugin in Rails 3.2.6 - my plugin is supposed to modify my User model (located in app/models/user.rb) - however, I cannot find the proper way to reference that file from the plugin in a require statement.

I tried require 'user', require 'app/models/user', and a bunch of stuff trying to use Rails.root and other variables - nothing works and I get an error "Uninitialized constant User" when trying to run the app.

Can someone please point me in the right direction? BTW, this plugin was build as a gem and is included in my Gemfile (which pulls it from github).

Thanks!

Jim
  • 2,300
  • 1
  • 19
  • 43

1 Answers1

2

If you are on ruby 1.9, you should be able to use require_relative

#assuming /lib/yourfile.rb
require_relative '../app/models/user.rb'

If you are on an older ruby, you might try

require File.dirname(__FILE__) + '../app/models/user.rb'
DVG
  • 17,392
  • 7
  • 61
  • 88
  • Didn't work in my case, but I think I have other issues with the plugin. Tried this with a quick test case and it works fine, so I am voting this the answer. Thanks! – Jim Jul 19 '12 at 02:30