rails active_storage:install IS NOT WORKING - ruby-on-rails

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:inperform'
/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:inblock 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:inrequire_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:inblock 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:inrequire'
/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:inload'
/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:incall'
/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.

Your problem is here:
require "active_storage"
You need to require the engine:
require "active_storage/engine"

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.

Try running command in the project root
bin/rails active_storage:install
or
rake active_storage:install

Related

Ruby on Rails will not register active_admin upon server startup (http://localhost:3001/admin)

I am currently creating my first React-on-Rails project. I have an issue with loading the server when trying to run the RoR api.
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 "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
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 ListOfIngredients
class Application < Rails::Application
# Initialize configuration defaults for originally generated
Rails version.
config.load_defaults 5.2
# Settings in config/environments/* take precedence over those
specified here.
# Application configuration can go into files in
config/initializers
# -- all .rb files in that directory are automatically loaded
after loading
# the framework and any gems in your application.
# 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
# Middleware for ActiveAdmin
config.middleware.use Rack::MethodOverride
config.middleware.use ActionDispatch::Flash
config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore
end
end
Gemfile.
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Build JSON APIs with ease. Read more:
https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
# Use Rack CORS for handling Cross-Origin Resource Sharing
(CORS), making cross-origin AJAX possible
# gem 'rack-cors'
group :development, :test do
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# 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
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'
end
group :production do
# Use postgres as the database for production
gem 'pg'
end
# ActiveAdmin
gem 'devise'
gem 'activeadmin'
# Windows does not include zoneinfo files, so bundle the tzinfo-
data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw,
:jruby]
I have also set up two controllers as follows.
api_controller.rb
class ApiController < ActionController::API
end
application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
end
When I am running rails on localhost 3001, I somehow still end up with the error message.
Sprockets::Rails::Helper::AssetNotFound in ActiveAdmin::Devise::Sessions#new
where are active admins assets supposed to go when rails 5 api doesn't contain an assets folder?
I'm pretty sure ActiveAdmin requires sprockets. Did you run?
rails generate devise:install
You might also need to run
rails generate devise:views
For more info on vies see the devise wiki
And perhaps a look at this answer and this one too
UPDATE:
If you are following instructions at this tutorial you might wanna try to comment out this line in application.rb
# require "sprockets/railtie"

Couldn't get active storage to install/work in rails 5.2.1

I tried this rails active_storage:install gives error but still I am getting the same error
Don't know how to build task 'active_storage:install'
rails 5.2.1
ruby 2.5.1
Couldn't get the server started as well.
/usr/local/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/railtie/configuration.rb:97:in `method_missing': undefined method `active_storage' for #<Rails::Application::Configuration:0x00007fc9493b7738> (NoMethodError)
I can get the server running if config.active_storage.service = :local is commented.
Sorry if I make any mistake, first time asking question here and newbie to RoR. Thanks!
Update:
config/application.rb:
require_relative 'boot'
require 'rails/all'
Bundler.require(*Rails.groups)
module Blogclass Application < Rails::Application
config.load_defaults 5.2
end
end
Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
gem 'rails', '~> 5.2.0'
gem 'sqlite3'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
gem 'capybara', '>= 2.15', '< 4.0'
gem 'selenium-webdriver'
gem 'chromedriver-helper'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Add require "active_storage/engine" under rails/all in your config/application.rb
require_relative 'boot'
require 'rails/all'
require "active_storage/engine"
Bundler.require(*Rails.groups)
module Blogclass Application < Rails::Application
config.load_defaults 5.2
end
end
Try to add
# config/application.rb
require "active_storage/engine"
For more details follow the link
application.rb file look like:
# application.rb
require_relative 'boot'
require "active_storage/engine"
require "rails"
# Pick the frameworks you want:
require "active_storage/engine"
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 "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 ArtsySpace
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.
end
end

puma fails to launch in production, throws Unable to load application: NoMethodError: `process' for #<Class:0x000000065f8ee8>

I have a Ruby on Rails app which runs perfectly in development, but once deployed to production, puma fails to launch. I've been debugging and googling this matter all day, to no avail.
I've tried completely wiping this app off the production server and started over from scratch. Same result.
I've tried different versions of puma -- no difference.
I've tried ordering the Gemfile differently -- no luck.
I've looked up known issues with ckeditor, mini_magick and carrierwave and have not found anything helpful thus far.
The mekilacms gem is a version of Wellspring that I have modified for this project. I have not found anything about Wellspring that appeared to be relevant.
Honestly I'm running out of ideas. Would really appreciate some help on this one.
Here is the puma.error.log which shows the issue I'm getting:
=== puma startup: 2017-05-08 17:35:06 -0400 ===
! Unable to load application: NoMethodError: undefined method `process' for #<Class:0x000000065f8ee8>
Did you mean? proc
bundler: failed to load command: puma (/home/www-data/apps/TrueSelfAcademy/shared/bundle/ruby/2.3.0/bin/puma)
This occurs whether run from Capistrano or from the command line as the deploying user.
This is what scrolls up on the command line:
Puma starting in single mode...
* Version 3.6.2 (ruby 2.3.0-p0), codename: Sleepy Sunday Serenity
* Min threads: 4, max threads: 16
* Environment: production
! Unable to load application: NoMethodError: undefined method `process' for #<Class:0x000000065f55b8>
Did you mean? proc
bundler: failed to load command: puma (/home/www-data/apps/TrueSelfAcademy /shared/bundle/ruby/2.3.0/bin/puma)
NoMethodError: undefined method `process' for #<Class:0x000000065f55b8>
Did you mean? proc
/home/www-data/apps/TrueSelfAcademy/shared/bundle/ruby/2.3.0 /gems/activerecord-5.0.1/lib/active_record/dynamic_matchers.rb:21:in `method_missing'
/var/www/apps/TrueSelfAcademy/shared/bundle/ruby/2.3.0/bundler/gems/ckeditor-11d3a5b90564/lib/ckeditor/backend/carrierwave.rb:14:in `block in extended'
/var/www/apps/TrueSelfAcademy/shared/bundle/ruby/2.3.0/bundler/gems/ckeditor-11d3a5b90564/lib/ckeditor/backend/carrierwave.rb:13:in `class_eval'
/var/www/apps/TrueSelfAcademy/shared/bundle/ruby/2.3.0/bundler/gems/ckeditor-11d3a5b90564/lib/ckeditor/backend/carrierwave.rb:13:in `extended'
/var/www/apps/TrueSelfAcademy/shared/bundle/ruby/2.3.0/bundler/gems/ckeditor-11d3a5b90564/lib/ckeditor/backend/carrierwave.rb:8:in `extend'
/var/www/apps/TrueSelfAcademy/shared/bundle/ruby/2.3.0/bundler/gems/ckeditor-11d3a5b90564/lib/ckeditor/backend/carrierwave.rb:8:in `included'
/var/www/apps/TrueSelfAcademy/shared/bundle/ruby/2.3.0/bundler/gems/MeKila-CMS-f997bb08ed5d/app/models/mekilacms/asset.rb:4:in `include'
/var/www/apps/TrueSelfAcademy/shared/bundle/ruby/2.3.0/bundler/gems/MeKila-CMS-f997bb08ed5d/app/models/mekilacms/asset.rb:4:in `<class:Asset>'
/var/www/apps/TrueSelfAcademy/shared/bundle/ruby/2.3.0/bundler/gems/MeKila-CMS-f997bb08ed5d/app/models/mekilacms/asset.rb:1:in `<top (required)>'
<...snip...>
Environment:
Rails 5.0.1,
Ruby 2.4.0rc1 (2016-12-12 trunk 57064) [x86_64-linux],
Ubuntu Server 16.04 (both prod and dev -- fully updated)
rvm 1.28.0,
bundler 1.14.6.
Capistrano Version: 3.8.1 (Rake Version: 12.0.0) is used to perform the deployment to production, which completes without error.
Here is the Gemfile:
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.1'
#use postgresql as the database
gem 'pg'
# Use Puma as the app server
gem 'puma', '3.6.2' # 3.7.0 has bug which results in no socket being created
# Use SCSS for stylesheets
gem 'sass-rails', '>= 5.0.6'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
# Sprockets
gem 'sprockets', '3.6.3'
# Use Bootstrap for site CSS
gem 'bootstrap-sass'
gem 'twitter-bootswatch-rails'
gem 'twitter-bootswatch-rails-helpers'
gem 'twitter-bootswatch-rails-fontawesome'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# 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.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'devise'
# gem 'toastr-rails'
gem 'remotipart', github: 'mshibuya/remotipart'
gem 'rails_admin', '>= 1.0.0.rc'
gem 'cancancan'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
gem 'spring-commands-rspec'
gem 'database_cleaner'
gem 'rspec-rails'
gem 'factory_girl_rails'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.0.5'
# 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'
gem 'capistrano', require: false
gem 'capistrano-rvm', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-bundler', require: false
gem 'capistrano3-puma', require: false
end
group :test do
gem 'capybara'
gem 'selenium-webdriver'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gembundle
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
# Capture user's timezone from their browser
gem 'browser-timezone-rails'
gem 'yaml_db'
gem 'rails-html-sanitizer'
# WYSIWYG functionality
gem 'carrierwave'
gem 'mini_magick'
gem 'ckeditor', :git => 'git://github.com/galetahub/ckeditor.git'
# CMS functionality
#gem 'mekilacms', path: '../mekilacms/'
gem 'mekilacms', :git => 'git#maitaikawika.hopto.org:david/MeKila-CMS.git'
Here is the Capfile:
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/puma'
install_plugin Capistrano::Puma
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
Let me know if there is anything else you need to look at...happy to include it in this post.
Thanks for your help!
David
In the interest of readability, here is the Asset model. I put it in comments and it looked hard to read...
class Ckeditor::Asset < ActiveRecord::Base
include ActiveRecord
include Ckeditor::Orm::ActiveRecord::AssetBase
include Ckeditor::Backend::CarrierWave
end
Here is the ckeditor_picture_uploader file. It does indeed have the "process"
call that puma is complaining about. I'm currently looking at asset paths and asset precompiles...
class CkeditorPictureUploader < CarrierWave::Uploader::Base
include Ckeditor::Backend::CarrierWave
include CarrierWave::MiniMagick
storage :file
def store_dir
"uploads/ckeditor/pictures/#{model.id}"
end
process :extract_dimensions
version :thumb do
process resize_to_fill: [118, 100]
end
version :content do
process resize_to_limit: [800, 800]
end
def extension_white_list
Ckeditor.image_file_types
end
end
Well this is weird, but solved.
The 'process' method that puma has been griping about is normally defined in the uploader/processing.rb file in the carrierwave gem.
I say normally because in mine, it wasn't. Somehow I wound up with a malformed processing.rb file which did not contain 'process' (nor it's evil twin 'process!') as it should have. I've strained my brain over how this happened and can't really account for it.
Nevertheless, grabbing a good copy of the file and replacing my malformed one with it solved the problem.
Seems almost anticlimactic, doesn't it?
Anyhow, onward and I'd like to thank #Md.FarhanMemon and #SachinSingh for their taking the time to respond and ask questions.

Ruby on Rails - cannot run the following command : rails generate rspec:install

I'm studying Rails tutorial Chapter 3.
I cannot execute the following command. If you have an idea to solve this problem, please tell me.
Thanks.
exec command
bundle exec rails generate rspec:install
Errors
/Users/mofuty/rails_projects/sample_app/config/application.rb:5:in `require': cannot load such file -- active_job/railtie (LoadError)
from /Users/mofuty/rails_projects/sample_app/config/application.rb:5:in `<top (required)>'
from /Users/mofuty/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.0.5/lib/rails/commands.rb:43:in `require'
from /Users/mofuty/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.0.5/lib/rails/commands.rb:43:in `<top (required)>'
from bin/rails:8:in `require'
from bin/rails:8:in `<main>'
Gemfile
source 'https://rubygems.org'
ruby '2.1.2'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.5'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.5'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
The following is apprication.rb. If you needs more details, please ask me.
config/application.rb
require File.expand_path('../boot', __FILE__)
# 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 "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 SampleApp class Application < Rails::Application
# 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.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true end end
Try bundle exec rails generate rspec:install
bundle exec is a Bundler command to execute a script in the context of the current bundle (the one from your directory's Gemfile)
It sounds as though your test suite is invoking some code with a dependency on the new ActiveJob framework that is part of Rails 4.
The error suggests that you do not have the railtie included in your config/application.rb file. If you open it, you'll likely find it is commented out, look for a line like this: # require "active_job/railtie"
If so, uncomment it. If that line is not included in the file, add require "active_job/railtie" on a new line after this require "active_model/railtie".
This will ensure that the active job railtie is loaded on Rails initialization.
Thanks for your advice. The problem is I executed rails new with rails 4.2.x. So, I rebuild the project with 4.0.5. Then I could executed bundle exec rails generate rspec:install. I appreciate you.

uninitialized constant FactoryGirl (NameError)

when i change in env.rb file under feature/support
require 'cucumber/rails'
require "#{Rails.root}/spec/factories"
and in gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.13'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
group :test do
gem 'cucumber-rails'
gem 'capybara'
gem 'database_cleaner'
gem 'factory_girl_rails', :require => false
end
group :development, :test do
gem 'rspec-rails'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
in spec/spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'factory_girl_rails'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
in spec/factories.rb
FactoryGirl.define do
factory :user do
first_name "John"
last_name "Doe"
admin false
end
end
uninitialized constant FactoryGirl (NameError)
/home/manish/change/test_cucumber/spec/factories.rb:1:in `<top (required)>'
/home/manish/change/test_cucumber/features/support/env.rb:8:in `<top (required)>'
/home/manish/.rvm/gems/ruby-1.9.3-p392/gems/cucumber-1.3.5/lib/cucumber/rb_support/rb_language.rb:122:in `load'
/home/manish/.rvm/gems/ruby-1.9.3-p392/gems/cucumber-1.3.5/lib/cucumber/rb_support/rb_language.rb:122:in `load_code_file'
/home/manish/.rvm/gems/ruby-1.9.3-p392/gems/cucumber-1.3.5/lib/cucumber/runtime/support_code.rb:180:in `load_file'
/home/manish/.rvm/gems/ruby-1.9.3-p392/gems/cucumber-1.3.5/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
/home/manish/.rvm/gems/ruby-1.9.3-p392/gems/cucumber-1.3.5/lib/cucumber/runtime/support_code.rb:82:in `each'
In spec/spec_helper.rb try adding
FactoryGirl.find_definitions
under
require 'factory_girl_rails'
I also faced this problem in Hartl tutorial.
If you are using Spork to speed up your tests and it is running in the background, you need to stop it (Ctrl+C) and restart it ($ bundle exec spork).

Resources