warning: shebang line ending with \r may cause problems. rails aborted - ruby-on-rails

I am setting up an existence Rails project using rbenv on Ubuntu 18.04. rbenv version is 1.1.2-11-gc46a970.
I have added .ruby-version file in the project root. When I run rbenv version I get the correct version of Ruby.
Now the issue is when I run rails s or rails test:system I get the following error:
/home/user/.rbenv/versions/2.5.0/bin/ruby: warning: shebang line ending with \r may cause problems rails aborted!
NameError: uninitialized constant URI::Generic
/home/my_project/config/application.rb:3:in `require'
/home/my_project/config/application.rb:3:in `<top (required)>'
/home/my_project/Rakefile:4:in `require_relative'
/home/my_project/Rakefile:4:in `<top (required)>'
/home/my_project/bin/rails:9:in `require'
/home/my_project/bin/rails:9:in `<top (required)>'
/home/my_project/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
(See full trace by running task with --trace)
But I am unable to get any clue how to fix this (as I am new to Ruby Rails.)
EDIT
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Dingoapp
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 = 'London'
config.serve_static_files = true
# 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
end
end

Related

"rails activestorage:update" errors out while upgrading to rails 6

I am performing an upgrade in rails version from 5.2.3 to 6.0.0 in our application and ended up with the following error when I run rails app:update and accept default changes.
Overwrite /Users/pk064816/solemnity/bin/setup? (enter "h" for help) [Ynaqdhm] y
force bin/setup
identical bin/yarn
rails active_storage:update
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/rule_monger-0.3.0/lib/rule_monger.rb:17: warning: already initialized constant HOST_PORT
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/netapp_oncommand_rest-0.2.1/lib/netapp_oncommand_rest.rb:21: warning: previous definition of HOST_PORT was here
rails aborted!
NameError: wrong constant name [[:error, ["detected unsupported rails version 6.0.0"], nil]]
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/newrelic_rpm-5.7.0.350/lib/new_relic/control/class_methods.rb:52:in `const_get'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/newrelic_rpm-5.7.0.350/lib/new_relic/control/class_methods.rb:52:in `load_framework_class'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/newrelic_rpm-5.7.0.350/lib/new_relic/control/class_methods.rb:32:in `new_instance'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/newrelic_rpm-5.7.0.350/lib/new_relic/control/class_methods.rb:13:in `instance'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/newrelic_rpm-5.7.0.350/lib/newrelic_rpm.rb:41:in `block in <class:Railtie>'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/initializable.rb:32:in `instance_exec'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/initializable.rb:32:in `run'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/initializable.rb:61:in `block in run_initializers'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/initializable.rb:60:in `run_initializers'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/application.rb:363:in `initialize!'
/Users/pk064816/ClosedStack/config/environment.rb:5:in `<main>'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/application.rb:339:in `require_environment!'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/application.rb:515:in `block in run_tasks_blocks'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/command.rb:48:in `invoke'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/commands.rb:18:in `<main>'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
bin/rails:8:in `<main>'
Tasks: TOP => active_storage:update => environment
(See full trace by running task with --trace)
After this, check Rails upgrade guide at https://guides.rubyonrails.org/upgrading_ruby_on_rails.html for more details about upgrading your app.
I do not really make use of activestorage inside the application and any configs specific to activestorage are only the defaults obtained from rails 5.2.3.
Here's what I have in my bin/rails:
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
and in bin/setup:
#!/usr/bin/env ruby
require 'fileutils'
# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
FileUtils.chdir APP_ROOT do
# This script is a way to setup or update your development environment automatically.
# This script is idempotent, so that you can run it at anytime and get an expectable outcome.
# Add necessary setup steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
# Install JavaScript dependencies
# system('bin/yarn')
# puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml')
# FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
# end
puts "\n== Preparing database =="
system! 'bin/rails db:prepare'
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end
and config/application.rb
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Solemnity
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
# Use Resque for our Active::Jobs
config.active_job.queue_adapter = :resque
# Add lib to autoload path
config.eager_load_paths << "#{Rails.root}/lib"
config.time_zone = 'Central Time (US & Canada)'
config.exceptions_app = self.routes
end
end
I tried to disable the use of activestorage, but that didn't really work! I am not entirely sure what's causing an error here and would really appreciate any help in working around this problem!

upgrading ruby 1.8.7 to 1.9.3 load error

I'm getting a load error when trying to upgrade to ruby 1.9.3 "small steps". There is a load error, but I am autoloading the lib directory. Does anyone know why this is happening?
application.rb:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
module MyApp
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.
# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W(#{config.root}/extras #{config.root}/lib)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# 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
# JavaScript files you want as :defaults (application.js is always included).
config.action_view.javascript_expansions[:defaults] = %w(delayed-observer jquery.rails)
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password, :cc, :account_token]
end
end
require 'lib/my-app/my-app'
console:
/Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require': cannot load such file -- lib/my-app/my-app (LoadError)
from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `block in require'
from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `block in load_dependency'
from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from /Users/jay/current_projects/my-app/config/application.rb:42:in `<top (required)>'
from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:28:in `block in <top (required)>'
from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Ruby 1.9 changed the default load path so it's often necessary to replace that with:
require_relative '../lib/my-app/my-app'
That way you can specify exactly where it is without having to change the $LOAD_PATH configuration.

Trouble starting my rails server all of a sudden

C:\Users\Josh\Sites\simple_cms>rails server
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-4.0.0/lib/active_support/va
lues/time_zone.rb:282: warning: circular argument reference - now
C:/Users/Josh/Sites/simple_cms/config/application.rb:7:in `<top (required)>': un
initialized constant Bundler (NameError)
from C:/Ruby22-x64/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_req
uire.rb:54:in `require'
from C:/Ruby22-x64/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_req
uire.rb:54:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.0.0/lib/rails/com
mands.rb:76:in `block in <top (required)>'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.0.0/lib/rails/com
mands.rb:73:in `tap'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.0.0/lib/rails/com
mands.rb:73:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_req
uire.rb:128:in `require'
from C:/Ruby22-x64/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_req
uire.rb:128:in `rescue in require'
from C:/Ruby22-x64/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_req
uire.rb:39:in `require'
from bin/rails:4:in `<main>'
C:\Users\Josh\Sites\simple_cms>
This is the file in config/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module SimpleCms
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
end
end

Rails Error - Uninitialized Constant

Upon setting up a new rails project I have come across the following issues on the rails s command
john-MacBook-Pro:coffee john$ rails s
/Users/john/Development/coffee/config/application.rb:10:in `<module:Coffee>': uninitialized constant Coffee::Rails::Application (NameError)
from /Users/john/Development/coffee/config/application.rb:9:in `<top (required)>'
from /Users/john/.rvm/gems/ruby-2.1.2/gems/railties-4.0.3/lib/rails/commands.rb:74:in `require'
from /Users/john/.rvm/gems/ruby-2.1.2/gems/railties-4.0.3/lib/rails/commands.rb:74:in `block in <top (required)>'
from /Users/john/.rvm/gems/ruby-2.1.2/gems/railties-4.0.3/lib/rails/commands.rb:71:in `tap'
from /Users/john/.rvm/gems/ruby-2.1.2/gems/railties-4.0.3/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
What exactly is causing this and how do I fix it?
Thanks for looking.
Application.rb file:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module Coffee
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
end
end
You seem to have called your application 'coffee'. This means that you have a module Coffee declaration in your config/application.rb file.
Rails uses the coffee-rails gem to support coffee script in a rails application and this also declares a module Coffee.
You have inadvertently created a name clash with your choice of application name.

Undefined variable or method 'config' for main:Object in application.rb for Rails 4?

I have come here as a last resort. I can't find a solution anywhere else on the internet. Thanks very much for your help. I am creating an application in rails 4, and I am loosely following along an old tutorial, which can be found here https://github.com/schneems/reddit_on_rails
When I try to run
rails generate devise user
I get this error message:
config/application.rb:25:in `<top (required)>': undefined local variable or method
`config' for main:Object (NameError)
from /home/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:82:in
`require'
from /home/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:82:in
`preload'
from /home/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:140:in
`serve'
from /home/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:128:in
`block in run'
from /home/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:122:in
`loop'
from /home/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:122:in `run'
from /home/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application/boot.rb:18:in
`<top (required)>'
from /home/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext
/kernel_require.rb:55:in `require'
from /home/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext
/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
Here is my application.rb file:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Stonedandalone
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 Recordauto-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
end
end
config.assets.initialize_on_precompile = false
#The last line is the one that caused the error.
Just move the config line up a few lines, to be inside of the class: class Application < Rails::Application.

Resources