Paperclip Issues on Rails 5

I created a new project with Rails 5.0.0 and Ruby 2.5 on my local mac with macOs 10.12. Now I'm trying to add paperclip to this project, but still no luck.

My model class is as follows:

class Photo < ApplicationRecord
  has_attached_file :file, styles: { big: '1280x1024>', small: '640x480>' }
  validates_attachment :file, content_type: { content_type: /\Aimage/ }, file_name: { matches: [/png\Z/i, /jpe?g\Z/i, /gif\Z/i] }, size: { less_than: 15.megabytes }
end

What version of paperclip I am trying, I don’t have a clip generator in my project, and I get errors like this when I try to call the model or its methods:

"NoMethodError (undefined method `has_attached_file' for Photo (call 'Photo.connection' to establish a connection):Class)"

When I add "include Paperclip :: Glue" as suggested here https://github.com/thoughtbot/paperclip/issues/705 the error changes to

NameError (uninitialized constant Photo::Paperclip)

Is there any way around this mess? > & L;

Link to paperclip issues https://github.com/thoughtbot/paperclip/issues/2555

+4
source share
1

, hamdi , .

Devise Paperclip, "include Paperclip:: Glue" Devise "expand Devise:: Models". - , , , , , ! , > < , .

, Rails 4:

2.5.0 :001 > Photo
 => Photo (call 'Photo.connection' to establish a connection)

Rails 5. , , "Photo.connection" . , ,

console do
  ActiveRecord::Base.connection
end

config/application.rb

0

Source: https://habr.com/ru/post/1693677/


All Articles