pat / gutentag

A good, simple, solid tagging extension for ActiveRecord.
MIT License
477 stars 36 forks source link

Can't use the gem outide rails? #16

Closed eqbal closed 9 years ago

eqbal commented 9 years ago

Thanks for this awesome gem. Anyway, I'm trying to gemify all the models and use it outside Rails (Grape) and now when I include the gem it doesn't seems to be working?

I added the gem to my models.gemspec like spec.add_dependency "gutentag","~> 0.6.0".

Now when I try to use has_many_tags in my model I get:

undefined local variable or method `has_many_tags' for #<Class:0x007fde9d9cac38> (NameError)

When I try to require the gem in the model I get this error:

/Users/info/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require':LoadError: cannot load such file -- rails/engine

Any help would be appreciated.

pat commented 9 years ago

I've just made some changes so it can be loaded without Rails, and it'll make sure the models are loaded automatically as well. The one catch is that you won't get the automatic migrations added in. I'm not yet sure if there's an elegant way to do this though…

If you have a moment and can test this in your gem before I push a new release, that'd be great:

gem 'gutentag',
  :git    => 'git://github.com/pat/gutentag.git',
  :branch => 'master',
  :ref    => 'b4a26561dd'
eqbal commented 9 years ago

Thanks for your swift response mate, This is awesome.

I have to say tho that I had to create my own implementation for tags.

Not sure if your changes working fine for me. What I did is I added the new gem to my Gemfile and then required that gem at the model and added has_many_tags burt got this error:

/Users/info/.rvm/gems/ruby-2.2.2/bundler/gems/gutentag-b4a26561ddbb/app/models/gutentag/tag.rb:7:in `class:Tag': uninitialized constant Gutentag::Tag::Rails (NameError)

On Thu, Aug 27, 2015 at 5:26 PM, Pat Allan notifications@github.com wrote:

I've just made some changes so it can be loaded without Rails, and it'll make sure the models are loaded automatically as well. The one catch is that you won't get the automatic migrations added in. I'm not yet sure if there's an elegant way to do this though…

If you have a moment and can test this in your gem before I push a new release, that'd be great:

gem 'gutentag', :git => 'git://github.com/pat/gutentag.git', :branch => 'master', :ref => 'b4a26561dd'

— Reply to this email directly or view it on GitHub https://github.com/pat/gutentag/issues/16#issuecomment-135451962.

eqbal commented 9 years ago

Just checked your modifications and I think this should work fine tho, I mean for:

+if defined?(Rails::Engine)

Aw checking why having some conflict with the name space and I'll keep u updated.

Cheers

On Thu, Aug 27, 2015 at 5:58 PM, Eqbal Eki eqbal.quran@gmail.com wrote:

Thanks for your swift response mate, This is awesome.

I have to say tho that I had to create my own implementation for tags.

Not sure if your changes working fine for me. What I did is I added the new gem to my Gemfile and then required that gem at the model and added has_many_tags burt got this error:

/Users/info/.rvm/gems/ruby-2.2.2/bundler/gems/gutentag-b4a26561ddbb/app/models/gutentag/tag.rb:7:in `class:Tag': uninitialized constant Gutentag::Tag::Rails (NameError)

On Thu, Aug 27, 2015 at 5:26 PM, Pat Allan notifications@github.com wrote:

I've just made some changes so it can be loaded without Rails, and it'll make sure the models are loaded automatically as well. The one catch is that you won't get the automatic migrations added in. I'm not yet sure if there's an elegant way to do this though…

If you have a moment and can test this in your gem before I push a new release, that'd be great:

gem 'gutentag', :git => 'git://github.com/pat/gutentag.git', :branch => 'master', :ref => 'b4a26561dd'

— Reply to this email directly or view it on GitHub https://github.com/pat/gutentag/issues/16#issuecomment-135451962.

pat commented 9 years ago

Ah, I had a reference to the Rails constant in Gutentag::Tag - fixed in 1e6f9ad0a9f69c1122314dd5ede283a9b2f7dfc6.

eqbal commented 9 years ago

Do I need to change the ref number or anything ?

As I'm getting this error for now:

/Users/info/.rvm/gems/ruby-2.2.2/bundler/gems/gutentag-b4a26561ddbb/app/models/gutentag/tag.rb:7:in `class:Tag': uninitialized constant Gutentag::Tag::Rails (NameError)

On Thu, Aug 27, 2015 at 6:21 PM, Pat Allan notifications@github.com wrote:

Ah, I had a reference to the Rails constant in Gutentag::Tag - fixed in 1e6f9ad https://github.com/pat/gutentag/commit/1e6f9ad0a9f69c1122314dd5ede283a9b2f7dfc6 .

— Reply to this email directly or view it on GitHub https://github.com/pat/gutentag/issues/16#issuecomment-135467000.

eqbal commented 9 years ago

Oh my bad, changed to 1e6f9ad and now working like charm.

Thanks mate

Eki

On Thu, Aug 27, 2015 at 7:03 PM, Eqbal Eki eqbal.quran@gmail.com wrote:

Do I need to change the ref number or anything ?

As I'm getting this error for now:

/Users/info/.rvm/gems/ruby-2.2.2/bundler/gems/gutentag-b4a26561ddbb/app/models/gutentag/tag.rb:7:in `class:Tag': uninitialized constant Gutentag::Tag::Rails (NameError)

On Thu, Aug 27, 2015 at 6:21 PM, Pat Allan notifications@github.com wrote:

Ah, I had a reference to the Rails constant in Gutentag::Tag - fixed in 1e6f9ad https://github.com/pat/gutentag/commit/1e6f9ad0a9f69c1122314dd5ede283a9b2f7dfc6 .

— Reply to this email directly or view it on GitHub https://github.com/pat/gutentag/issues/16#issuecomment-135467000.

pat commented 9 years ago

Just released 0.7.0 with these changes :)

eqbal commented 9 years ago

Awesome.

Cheers mate.

On Thursday, August 27, 2015, Pat Allan notifications@github.com wrote:

Just released 0.7.0 with these changes :)

— Reply to this email directly or view it on GitHub https://github.com/pat/gutentag/issues/16#issuecomment-135541685.