I updated a Rails 2.3 app to 3.2 and it seemed to be a pretty simple process but when setting up the Figaro gem I came across this error:
C:\Sites\JustManage>rails generate figaro:install
C:/Sites/JustManage/config/environment.rb:5:in `<top (required)>': uninitialized
constant Projectmanagement (NameError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
/lib/rails/application.rb:103:in `require_environment!'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
/lib/rails/commands.rb:25:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Here is what my environment.rb looks like:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Projectmanagement::Application.initialize!
Here is my application.rb file:
require File.expand_path('../application', __FILE__)
require 'rails/all'
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module Railsapp
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [
:password,
:password_clear,
:password_verify
]
config.assets.enabled = true
config.assets.version = '1.0'
end
end
I've never run into this error before and don't know why it's happening.
It seems like the name of your application is not the same in the different places it needs to appear in. Check the following files and see if they contain either Projectmanagement::Application or Railsapp::Application:
config/application.rb (Actually initializes the constant)
config/environment.rb
config/environments/development.rb
config/environments/production.rb
config/environments/test.rb
config/initializers/secret_token.rb
config/initializers/session_store.rb
config/mongoid.yml (if using Mongoid)
config/routes.rb
config.ru
Rakefile
app/views/layouts/application.html.erb, in title tag
Then pick a name (either Projectmanagement or Railsapp) and change all the names in the above files so they match. That should resolve the uninitialized constant error you are having.
I can't be certain that they are not errors from copy/pasting, but your application.rb appears to be incorrect. Issues I see:
L1: You are requiring application.rb a second time where you mean to be requiring boot.rb.
L12: The name of this module (i.e. the name of your app) is not consistent here with what is in your environment.rb file (Railsapp vs. Projectmanagement).
The second issue is actually causing the error you are seeing - you have not defined the Projectmanagement constant before calling a method on it.
Related
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
How do I resolve the following error?
bundle exec rake db:create
rake aborted!
no such file to load -- xpath
/Users/michael/Sites/appsbar/config/application.rb:13:in `<top (required)>'
/Users/michael/Sites/appsbar/Rakefile:5:in `require'
/Users/michael/Sites/appsbar/Rakefile:5:in `<top (required)>'
with trace
bundle exec rake db:create --trace
rake aborted!
no such file to load -- xpath
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/capybara-2.0.1/lib/capybara.rb:3:in `<top (required)>'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/bundler-1.2.2/lib/bundler/runtime.rb:68:in `require'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/bundler-1.2.2/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/bundler-1.2.2/lib/bundler/runtime.rb:66:in `each'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/bundler-1.2.2/lib/bundler/runtime.rb:66:in `block in require'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/bundler-1.2.2/lib/bundler/runtime.rb:55:in `each'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/bundler-1.2.2/lib/bundler/runtime.rb:55:in `require'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/bundler-1.2.2/lib/bundler.rb:128:in `require'
/Users/michael/Sites/appsbar/config/application.rb:13:in `<top (required)>'
/Users/michael/Sites/appsbar/Rakefile:5:in `require'
/Users/michael/Sites/appsbar/Rakefile:5:in `<top (required)>'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/rake-10.0.2/lib/rake/rake_module.rb:25:in `load'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/rake-10.0.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/rake-10.0.2/lib/rake/application.rb:581:in `raw_load_rakefile'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/rake-10.0.2/lib/rake/application.rb:87:in `block in load_rakefile'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/rake-10.0.2/lib/rake/application.rb:158:in `standard_exception_handling'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/rake-10.0.2/lib/rake/application.rb:86:in `load_rakefile'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/rake-10.0.2/lib/rake/application.rb:70:in `block in run'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/rake-10.0.2/lib/rake/application.rb:158:in `standard_exception_handling'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/rake-10.0.2/lib/rake/application.rb:68:in `run'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/gems/rake-10.0.2/bin/rake:37:in `<top (required)>'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/bin/rake:19:in `load'
/Users/michael/.rbenv/versions/1.9.2-p290/gemsets/appsbar/bin/rake:19:in `<main>'
application.rb
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module Appsbar
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)
# 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
# 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]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
# Devise recommendation:
# If you are deploying Rails 3.1 on Heroku, you may want to set:
# config.assets.initialize_on_precompile = false
# On config/application.rb forcing your application to not access the DB
# or load models when precompiling your assets.
config.assets.initialize_on_precompile = false
end
end
Rakefile
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
Appsbar::Application.load_tasks
See
https://github.com/jnicklas/capybara/issues/882
Some people have fixed this issue by redoing "bundle update capybara", this appears to fix some kind of bundler dependency weirdness.
/full/path/to/the/gem/being/used/bin/gem install 'xpath' please ensure you're using the right gem binary, for example, my ruby install is in $HOME/.rvm/bin/ruby and gem is in $HOME/.rvm/gems/ruby-1.9.3-p327/bin. It's also to be found in /usr/bin. I always run it as $HOME/.rvm/gems/ruby-1.9.3-p327/bin/ruby $HOME/.rvm/gems/ruby-1.9.3-p327/bin/gem to not be ambiguous and to ensure I'm getting the right one.
I'm just starting with rails and I'm having the following error when starting the server.
$ rails s
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/linecache19-0.5.12/lib/tracelines19.rb:12:in `require': dlopen(/usr/local/rvm/gems/ruby-1.9.3-p194/gems/linecache19-0.5.12/lib/trace_nums19.bundle, 9): Symbol not found: _ruby_current_thread (LoadError)
Referenced from: /usr/local/rvm/gems/ruby-1.9.3-p194/gems/linecache19-0.5.12/lib/trace_nums19.bundle
Expected in: flat namespace in /usr/local/rvm/gems/ruby-1.9.3-p194/gems/linecache19-0.5.12/lib/trace_nums19.bundle - /usr/local/rvm/gems/ruby-1.9.3-p194/gems/linecache19-0.5.12/lib/trace_nums19.bundle
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/linecache19-0.5.12/lib/tracelines19.rb:12:in `rescue in <module:TraceLineNumbers>'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/linecache19-0.5.12/lib/tracelines19.rb:8:in `<module:TraceLineNumbers>'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/linecache19-0.5.12/lib/tracelines19.rb:6:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/linecache19-0.5.12/lib/linecache19.rb:69:in `require'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/linecache19-0.5.12/lib/linecache19.rb:69:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p194#global/gems/bundler-1.1.5/lib/bundler/runtime.rb:68:in `require'
from /usr/local/rvm/gems/ruby-1.9.3-p194#global/gems/bundler-1.1.5/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /usr/local/rvm/gems/ruby-1.9.3-p194#global/gems/bundler-1.1.5/lib/bundler/runtime.rb:66:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p194#global/gems/bundler-1.1.5/lib/bundler/runtime.rb:66:in `block in require'
from /usr/local/rvm/gems/ruby-1.9.3-p194#global/gems/bundler-1.1.5/lib/bundler/runtime.rb:55:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p194#global/gems/bundler-1.1.5/lib/bundler/runtime.rb:55:in `require'
from /usr/local/rvm/gems/ruby-1.9.3-p194#global/gems/bundler-1.1.5/lib/bundler.rb:119:in `require'
from /Users/Crysfel/Sites/rails/quizzpot/config/application.rb:13:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:53:in `require'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:53:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I'm using:
Rails 3.2.8
ruby 1.9.3p194
Here's my config/application.rb file:
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module Quizzpot
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)
# 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
# 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]
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
# config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
end
end
The stack trace shows you are having a problem with the linecache19 gem. A Google search shows that others have encountered the same problem: it seems to be an incompatibility between that gem and Ruby 1.9.3.
Is linecache19 in your Gemfile? If so, can you just remove it? (Do you really need it?) If it's not in the Gemfile, look in Gemfile.lock and see if it's listed as a dependency of one of your other gems.
I try to use this tutorial, but have some problems with scaffold generation code.
application.rb
Bundler.require(:default, Rails.env) if defined?(Bundler)
#if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
# Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
#end
Take solution from this topic, but not well for this problem.
Log:
C:\Users\Evgeny\Rails_projects\demo_app>rails generate scaffold User name:string
email:string
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/ra
iltie/configuration.rb:77:in `method_missing': undefined method `assets' for #<R
ails::Application::Configuration:0x3a03248> (NoMethodError)
from C:/Users/Evgeny/Rails_projects/demo_app/config/application.rb:55:in
`<class:Application>'
from C:/Users/Evgeny/Rails_projects/demo_app/config/application.rb:14:in
`<module:DemoApp>'
from C:/Users/Evgeny/Rails_projects/demo_app/config/application.rb:13:in
`<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.0.9
/lib/rails/commands.rb:15:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.0.9
/lib/rails/commands.rb:15:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Config app:
source 'http://rubygems.org'
gem 'rails', '3.0.9'
gem 'sqlite3', '1.3.3'
Rails asset pipeline isn't available until Rails 3.1 and later. I'm guessing that on line 55 of C:/Users/Evgeny/Rails_projects/demo_app/config/application.rb, you have a config.assets line which is causing the issue. Either remove that line or upgrade to Rails 3.1 or 3.2
It's something with assets. I think you need to upgrade your rails to 3.1 at least. 3.2.3 is better.
Try to create new project with last version of rails 3.2.3.
or try this solution http://railscasts.com/episodes/282-upgrading-to-rails-3-1 or last chapter of tutorial book http://russian.railstutorial.org/chapters/rails-3-1#top .
One more solution without upgrading, but I'm not sure. In your config/application.rb try to find config.assets.enabled and set it to false.
just started building out a rails project from scratch after months of re-purposing of older code. the new project wont allow me to run rails server from the command line. i'm getting an error reporting the problem is in the application.rb file
rails_projects/platform/config/application.rb:7: undefined method `groups' for Rails:Module (NoMethodError)
from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/commands.rb:28:in `require'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/commands.rb:28
from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/commands.rb:27:in `tap'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/commands.rb:27
from script/rails:6:in `require'
from script/rails:6
application.rb file looks like this:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module Platform
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [:password]
config.assets.enabled = true
config.assets.version = '1.0'
end
end
The Rails.groups method was something that was added in Rails 3.1. By the look of it, you're still using Rails 3.0.9. Change the version number for Rails in your Gemfile to 3.1.1 and run bundle update rails to fix this problem.