2017-07-01 11 views
1

railsアプリケーションを作って、act-as-taggable-on gemを追加し、rake db:migrateを実行し、フィールドをArticle.rbに追加しました。私はレール5.1アプリでこのエラーが発生したようです。私はそれが何であるか把握できません。acts_as_taggable_on GailsがRails 5で動作していない

GemFile

gem 'acts-as-taggable-on', '~> 4.0' 

Article.rb

class Article < ApplicationRecord 
    include TheComments::Commentable 

    acts_as_taggable_on :tags 

     belongs_to :user 

     # Denormalization methods 
     # Check the documentation for information on advanced usage 
     def commentable_title 
     title 
     end 

     def commentable_url 
     ['', self.class.to_s.tableize, id].join('/') 
     end 

     def commentable_state 
     :published.to_s 
     end 
    end 

私はこのエラーを取得するしかし:

Running via Spring preloader in process 18395 
Loading development environment (Rails 5.1.2) 
2.4.0-rc1 :001 > Article 
NoMethodError: undefined method `acts_as_taggable_on' for Article (call 'Article.connection' to establish a connection):Class 
    from app/models/article.rb:6:in `<class:Article>' 
    from app/models/article.rb:1:in `<top (required)>' 
    from (irb):1 
2.4.0-rc1 :002 > Article 
NoMethodError: undefined method `acts_as_taggable_on' for Article (call 'Article.connection' to establish a connection):Class 
    from app/models/article.rb:6:in `<class:Article>' 
    from app/models/article.rb:1:in `<top (required)>' 
+0

あなたはGemfileに宝石を追加した後 'バンドルinstall'を実行しましたか?文字列とアプリケーションを再起動しましたか? – spickermann

答えて

1

問題の理由は、のバージョンであります宝石。あなたが使っている宝石のバージョンはRails 5をサポートしていません。

githubからgemを直接取り出してエラーを解決できます。そのために は自分gemfileにコードの下に使用します。

gem 'acts-as-taggable-on', :git => 'https://github.com/mbleigh/acts-as-taggable-on' 
+0

私は新しい宝石を更新し、スキーマを再インストールしました。rake db:migrateを実行しても、同じエラーが表示されます。この方法はまだ認識されていないようです。 – applejuiceteaching

+0

LoadError:そのようなファイルを読み込むことができません - taggable-onとして動作します – applejuiceteaching

+0

https://github.com/mbleigh/acts-as-http: taggable-on#インストール。はいの場合は、詳細なエラーを提出してください。 –

0

彼らが言及されていないバージョン5を持っています。マニュアルによれば、バージョン4はRails 4と5の両方で不正確です。私は次のものを私のGemfileに追加して動作させました。 GitHubリンクは私の参照点です。

gem "acts-as-taggable-on", "~> 5.0" 

https://github.com/mbleigh/acts-as-taggable-on/issues/866

関連する問題