rails active_storage:install 不工作
rails active_storage:install IS NOT WORKING
我已将我的 rails api 应用程序从 5.1 更新到 5.2。
我只使用 rails api。
我正在尝试使用活动存储。我认为问题出在 config/application.rb
.
中的行 config.api_only = true
我做了很多 google 但在 rails api.
中没有找到如何使用活动存储的任何东西
这是我的 Gemfile
:
source 'https://rubygems.org'
ruby '2.5.1'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
gem 'rails', '~> 5.2.0'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.7'
gem 'rack-cors'
# Auth
gem 'bcrypt'
gem 'jwt'
#Media file upload
gem 'activestorage'
# gem 'devise', '4.4.3'
# gem 'devise-jwt', '~> 0.5.6'
gem 'active_model_serializers', '~> 0.10.0', require: true
# backgroud jobs
gem 'sidekiq'
# fast boot
gem 'bootsnap', require: false
group :development, :test do
gem 'rspec-rails', '~> 3.7'
gem 'brakeman'
gem 'rubocop'
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'foreman'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'pry'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'annotate'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
这是我的 config/application.rb
require_relative 'boot'
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "active_storage"
# require "sprockets/railtie"
require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module CelebrationBackend
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Only loads a smaller set of middleware suitable for API only apps.
# Middleware like session, flash, cookies can be added back manually.
# Skip views, helpers and assets when generating a new resource.
config.api_only = true
config.active_job.queue_adapter = :sidekiq
config.autoload_paths << Rails.root.join('lib')
end
end
同时 运行 rails activestorage:install
进入控制台。
我收到以下错误:
rails中止!
不知道如何构建任务 'activestorage:install'(参见 --tasks)
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/railties-5.2.0/lib/rails/commands/rake/rake_command.rb:23:in block in perform'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/railties-5.2.0/lib/rails/commands/rake/rake_command.rb:20:in
执行'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/railties-5.2.0/lib/rails/command.rb:48:in invoke'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/railties-5.2.0/lib/rails/commands.rb:18:in
'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in require'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in
block in require_with_bootsnap_lfi'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in register'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in
require_with_bootsnap_lfi'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in require'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in
block in require'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in load_dependency'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in
require'
/home/sourabh/dev/celebration/bin/rails:9:in <top (required)>'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in
load'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in call'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/spring-2.0.2/lib/spring/client/command.rb:7:in
call'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/spring-2.0.2/lib/spring/client.rb:30:in run'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/spring-2.0.2/bin/spring:49:in
'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/spring-2.0.2/lib/spring/binstub.rb:31:in load'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/spring-2.0.2/lib/spring/binstub.rb:31:in
'
/home/sourabh/dev/celebration/bin/spring:15:in require'
/home/sourabh/dev/celebration/bin/spring:15:in
'
bin/rails:3:在load'
bin/rails:3:in
'
(使用 --trace 查看 运行 任务的完整跟踪)
我不明白我做错了什么。
在项目根目录中尝试 运行 命令
bin/rails activestorage:install
或
rake active_storage:install
您的问题在这里:
require "active_storage"
您需要要求引擎:
require "active_storage/engine"
目前的rails官方文档都在讲新的应用。但
如果您要升级 5.2 之前的应用,您必须添加 或取消注释 application.rb
require "active_storage/engine"
对于新的应用程序,这将已经添加。
我已将我的 rails api 应用程序从 5.1 更新到 5.2。
我只使用 rails api。
我正在尝试使用活动存储。我认为问题出在 config/application.rb
.
config.api_only = true
我做了很多 google 但在 rails api.
中没有找到如何使用活动存储的任何东西这是我的 Gemfile
:
source 'https://rubygems.org'
ruby '2.5.1'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
gem 'rails', '~> 5.2.0'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.7'
gem 'rack-cors'
# Auth
gem 'bcrypt'
gem 'jwt'
#Media file upload
gem 'activestorage'
# gem 'devise', '4.4.3'
# gem 'devise-jwt', '~> 0.5.6'
gem 'active_model_serializers', '~> 0.10.0', require: true
# backgroud jobs
gem 'sidekiq'
# fast boot
gem 'bootsnap', require: false
group :development, :test do
gem 'rspec-rails', '~> 3.7'
gem 'brakeman'
gem 'rubocop'
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'foreman'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'pry'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'annotate'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
这是我的 config/application.rb
require_relative 'boot'
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "active_storage"
# require "sprockets/railtie"
require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module CelebrationBackend
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Only loads a smaller set of middleware suitable for API only apps.
# Middleware like session, flash, cookies can be added back manually.
# Skip views, helpers and assets when generating a new resource.
config.api_only = true
config.active_job.queue_adapter = :sidekiq
config.autoload_paths << Rails.root.join('lib')
end
end
同时 运行 rails activestorage:install
进入控制台。
我收到以下错误:
rails中止!
不知道如何构建任务 'activestorage:install'(参见 --tasks)
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/railties-5.2.0/lib/rails/commands/rake/rake_command.rb:23:in block in perform'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/railties-5.2.0/lib/rails/commands/rake/rake_command.rb:20:in
执行'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/railties-5.2.0/lib/rails/command.rb:48:in invoke'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/railties-5.2.0/lib/rails/commands.rb:18:in
'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in require'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in
block in require_with_bootsnap_lfi'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in register'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in
require_with_bootsnap_lfi'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in require'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in
block in require'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in load_dependency'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in
require'
/home/sourabh/dev/celebration/bin/rails:9:in <top (required)>'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in
load'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in call'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/spring-2.0.2/lib/spring/client/command.rb:7:in
call'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/spring-2.0.2/lib/spring/client.rb:30:in run'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/spring-2.0.2/bin/spring:49:in
'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/spring-2.0.2/lib/spring/binstub.rb:31:in load'
/home/sourabh/.rvm/gems/ruby-2.5.1@celeb/gems/spring-2.0.2/lib/spring/binstub.rb:31:in
'
/home/sourabh/dev/celebration/bin/spring:15:in require'
/home/sourabh/dev/celebration/bin/spring:15:in
'
bin/rails:3:在load'
bin/rails:3:in
'
(使用 --trace 查看 运行 任务的完整跟踪)
我不明白我做错了什么。
在项目根目录中尝试 运行 命令
bin/rails activestorage:install
或
rake active_storage:install
您的问题在这里:
require "active_storage"
您需要要求引擎:
require "active_storage/engine"
目前的rails官方文档都在讲新的应用。但
如果您要升级 5.2 之前的应用,您必须添加 或取消注释 application.rb
require "active_storage/engine"
对于新的应用程序,这将已经添加。