Ruby on rails 未定义的方法'image';对于#<;ActiveStorage::附件:

Ruby on rails 未定义的方法'image';对于#<;ActiveStorage::附件:,ruby-on-rails,model-view-controller,methods,dropzone.js,rails-activestorage,Ruby On Rails,Model View Controller,Methods,Dropzone.js,Rails Activestorage,我正在尝试使用DropzoneJS和活动存储实现照片上传,但在这一点上,我的应用程序抛出了未定义的方法“image”# 车型/汽车.rb index.html.erb 我的档案。是否需要取消对图像处理gem的注释以启用和使用 source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '2.6.5' # Bundle edge R

我正在尝试使用DropzoneJS和活动存储实现照片上传,但在这一点上,我的应用程序抛出了未定义的方法“image”#

车型/汽车.rb

index.html.erb

我的档案。是否需要取消对图像处理gem的注释以启用和使用

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.5'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
#gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  #Provides better error page for Rails and other Rack apss.
  gem 'better_errors', '~> 2.5', '>= 2.5.1'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'bootstrap', '~> 4.4.1'

gem 'devise', '~> 4.7', '>= 4.7.1'
gem 'jquery-rails'

gem 'omniauth', '~> 1.9'

gem 'omniauth-facebook', '~> 5.0'

#new gems
group :development, :production do
  gem 'capistrano', '~> 3.11', require: false
  gem 'capistrano-bundler', require: false
  gem 'capistrano-rails', '~> 1.4', require: false
  gem 'capistrano-passenger', '~> 0.2.0'
  gem 'capistrano-rbenv', '~> 2.1', '>= 2.1.4', github: 'capistrano/rbenv', require: false
end
#gem 'capistrano', '~> 3.11'
#gem 'capistrano-rails', '~> 1.4'
#gem 'capistrano-passenger', '~> 0.2.0'
#gem 'capistrano-rbenv', '~> 2.1', '>= 2.1.4'

gem 'jquery-ui-rails', '~> 5.0'
源代码'https://rubygems.org'
git|u源(:github){| repo |“https://github.com/#{repo}.git}
ruby“2.6.5”
#捆绑边缘Rails:gem'Rails',github'Rails/Rails'
gem'rails',“~>6.0.0”
#使用sqlite3作为活动记录的数据库
gem'sqlite3',“~>1.4”
#宝石“pg”
#使用Puma作为应用程序服务器
宝石“彪马”,“大于3.11”
#将SCS用于样式表
gem'sass rails',“~>5”
#像JavaScript一样的透明应用程序。阅读更多:https://github.com/rails/webpacker
gem'webpacker',“~>4.0”
#Turbolinks使web应用程序的导航速度更快。阅读更多:https://github.com/turbolinks/turbolinks
gem“涡轮链接”,“大于5”
#轻松构建JSON API。阅读更多:https://github.com/rails/jbuilder
gem'jbuilder',“~>2.7”
#使用Redis适配器在生产中运行操作电缆
#gem'redis',“~>4.0”
#使用具有\u安全\u密码的活动模型
#gem'bcrypt',“~>3.1.7”
#使用活动存储变体
#gem‘图像处理’,“~>1.2”
#通过缓存减少启动时间;config/boot.rb中需要
gem'bootsnap','>=1.4.2',require:false
小组:开发,:测试
#在代码中的任意位置调用“byebug”以停止执行并获得调试器控制台
gem'byebug',平台:[:mri,:mingw,:x64_mingw]
结束
小组:发展怎么办
#在异常页面上或通过调用代码中的任意位置的“控制台”访问交互式控制台。
gem“web控制台”,“>=3.3.0”
gem'listen','>=3.0.5','<3.2'
#Spring通过让应用程序在后台运行来加速开发。阅读更多:https://github.com/rails/spring
宝石“春天”
gem‘SpringWatcherListen’,“~>2.0.0”
#为Rails和其他机架式APS提供更好的错误页面。
gem“更好的错误”,“大于2.5”,“大于等于2.5.1”
结束
组:测试do
#增加了对Capybara系统测试和selenium驱动程序的支持
gem‘水豚’,“>=2.15”
gem“selenium webdriver”
#轻松安装和使用web驱动程序以使用浏览器运行系统测试
gem“webdrivers”
结束
#Windows不包括zoneinfo文件,因此捆绑tzinfo数据
gem'tzinfo data',平台:[:mingw,:mswin,:x64_mingw,:jruby]
gem“引导程序”,“~>4.4.1”
宝石“设计”,“大于4.7”,“大于等于4.7.1”
gem'jqueryrails'
gem'omniauth',“~>1.9”
gem'omniauth facebook',“~>5.0”
#新宝石
组:开发,:生产
gem'capistrano','~>3.11',要求:false
gem“capistrano捆绑机”,要求:false
gem'capistrano rails','~>1.4',require:false
gem“capistrano乘客号”,“~>0.2.0”
gem'capistrano rbenv','~>2.1','>=2.1.4',github'capistrano/rbenv',require:false
结束
#宝石“capistrano”,“~>3.11”
#gem“capistrano rails”,“~>1.4”
#gem“capistrano乘客号”,“~>0.2.0”
#gem“capistrano rbenv”、“~>2.1”、“>=2.1.4”
gem'jqueryuirails',“~>5.0”
这有点让人困惑,因为我是新手

我要为
照片创建控制器吗

我也需要添加某种宝石吗


如何修复此问题?

您不需要创建其他模型。您只需确保将
添加到模型文件中,并使用
url\u(self.photos[0])
获取url即可。您也可以使用
self.photos[0]。服务url

评论后编辑:

因为封面照片上没有定义图像方法,所以您得到的命名错误是相同的。纠正错误的一种方法就是这样

def封面照片(尺寸x,尺寸y)
如果self.photos.length>0
self.photos[0]。变量(将大小调整到大小限制:[size\u x,size\u y])。已处理。服务\u url
其他的
“blank.jpg”
结束
结束

您不需要创建其他模型。您只需确保将
添加到模型文件中,并使用
url\u(self.photos[0])
获取url即可。您也可以使用
self.photos[0]。服务url

评论后编辑:

因为封面照片上没有定义图像方法,所以您得到的命名错误是相同的。纠正错误的一种方法就是这样

def封面照片(尺寸x,尺寸y)
如果self.photos.length>0
self.photos[0]。变量(将大小调整到大小限制:[size\u x,size\u y])。已处理。服务\u url
其他的
“blank.jpg”
结束
结束

谢谢。是的,我的车里已经有很多照片了。请你解释一下我应该怎么做?因为它不工作,我仍然收到错误。你能分享错误信息吗?这可能与尺寸有关。为了获得不同尺寸的图像,需要使用不同的尺寸。()这是一个命名错误
未定义的方法
图像#将所有
更改为
谢谢。是的,我的车里已经有很多照片了。请你解释一下我应该怎么做?因为它不工作,我仍然收到错误。你能分享错误信息吗?这可能与尺寸有关。为了获得不同尺寸的图像,需要使用不同的尺寸。()这是一个命名错误
未定义的方法
image'#将所有
更改为