I have updated my rails api application from 5.1 to 5.2.
I am using rails api only.
I am trying to use the active storage. I think the problem is due to the line config.api_only = true
in config/application.rb
.
I did lot of google but did not find any thing how to use active storage in rails api.
Here is my 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]
Here is my 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
While running the rails activestorage:install
in to console.
I am getting the following error:
rails aborted!
Don't know how to build task 'activestorage:install' (see --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
perform'
/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:in load'
bin/rails:3:in
'
(See full trace by running task with --trace)
I am not getting the exact thing what I am doing wrong.
The current rails official documents talks about the new application. But
if you're upgrading a pre 5.2 app, you have to add or uncomment the field in application.rb
require "active_storage/engine"
For the new application, this will be already added.
Your problem is here:
require "active_storage"
You need to require the engine:
require "active_storage/engine"
Try running command in the project root
bin/rails activestorage:install
or
rake active_storage:install
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With