2016-10-30 3 views
0

https://github.com/thoughtbot/paperclipのドキュメントに従って、イメージアップロードのためにアプリにpaperclipをインストールするようにしました。私は現在、gem 'paperclip'、 '〜> 5.0.0.beta1'を使用しています。移行を実行した後、4つの列が正しくスキーマに追加されました。私のActiveRecordモデルのための未定義のメソッド "has_attached_file"

t.string "picture_file_name" 
t.string "picture_content_type" 
t.integer "picture_file_size" 
t.datetime "picture_updated_at" 

私のペーパークリップは正しくインストールする必要があります。しかし、ときに私は私のモデルクラスに次の2行を追加するために進めた:

has_attached_file :picture, styles: { medium: "300*300>", thumb: "100*100" }, default_url: "/images/start_project3.jpg" 
    validates_attachment_content_type :picture, content_type: /\Aimage\/.*\Z/ 

すべてが壊れました。私は以前のバージョン4.3.0からに、クリップの複数のバージョンを試してみました

NoMethodError: undefined method `has_attached_file' for #<Class:0x0055bd71ec0228> 

:私は、検索、またはレールコンソールでモデルクラスに関連したものを作成しようと、それは次のエラーで私を叫びますペーパークリップの最新バージョンですが、問題は解決しません。変更と移行の間にサーバーを再起動しましたが、それでも問題は解決しませんでした。これは私が行ったマイグレーションです:

私は今何をすべきかについて完全に失われています。私は何が起こったのかわからない

source 'https://rubygems.org' 


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '4.2.7.1' 
# Use postgresql as the database for Active Record 
gem 'pg', '~> 0.15' 
# Use SCSS for stylesheets 
gem 'sass-rails', '~> 5.0' 
# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 
# Use CoffeeScript for .coffee assets and views 
gem 'coffee-rails', '~> 4.1.0' 
# See https://github.com/rails/execjs#readme for more supported runtimes 
# gem 'therubyracer', platforms: :ruby 

# Use jquery as the JavaScript library 
gem 'jquery-rails' 
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '~> 2.0' 
# bundle exec rake doc:rails generates the API under doc/api. 
gem 'sdoc', '~> 0.4.0', group: :doc 

# Use ActiveModel has_secure_password 
gem 'bcrypt', '~> 3.1.7' 
gem 'pry-rails' 
gem 'annotate' 
# Use Unicorn as the app server 
# gem 'unicorn' 
gem 'faker' 
# Use Capistrano for deployment 
# gem 'capistrano-rails', group: :development 
gem 'pg_search' 
gem 'paperclip', '~> 5.0.0.beta1' 
# gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git" 
# gem "paperclip", "~> 4.3" 

group :development, :test do 
    # Call 'byebug' anywhere in the code to stop execution and get a debugger console 
    gem 'byebug' 
    gem 'faker' 
end 

group :development do 
    # Access an IRB console on exception pages or by using <%= console %> in views 
    gem 'web-console', '~> 2.0' 

    # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 
    gem 'spring' 
end 

group :production do 
    gem 'newrelic_rpm' 
    gem 'rails_12factor' # error feedback 
end 

答えて

1

: これは私の宝石のファイルです。私はdbロールバックをやり終え、もう一度移行を再移行しました。その後、バックグラウンドで動作しているすべての端末を終了し、すべてを再起動しました。今のところ働いています。

+0

'$ rails console'でペーパークリップの添付ファイルを使ってモデルを呼び出すと、このエラーメッセージが突然表示されました。 '$ rails server 'に問題はなかった。私は何が起こったのか分からないが、ターミナルを再起動すると私のためにやった。 – Arta

関連する問題