Getting a NameError when I run the command rails server - ruby-on-rails

I'm new to Ruby and am following the Michael Hartl's tutorial. I'm still on chapter 1.
It says
undefined local variable or method 'first_app' for main:Object (NameError)
which is in my development.rb line 1.
Firstapp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
I followed other questions on StackOverflow with no solution. Some of them require to changed my app name from
Rails.application.configure do
to
First_app::Application.configure do
which didn't resolve anything. Oh and if it helps, I'm using Windows.

When you ran the rails new command it should have properly set your app's name. I think what happened is you probably ran rails new firstapp instead of rails new first_app. ChangeFirst_app::Application.configure do to FirstApp::Application.configure do. You should also probably do a search in your project for Firstapp or First_App and change those as well.

It had something to do with my Gem file apparently. I didn't edit it this and left it alone, the application ended up compiling without any errors. I think it has something to do with SQLite3 gem that I'm not properly doing something regarding version.

Related

Display the full error in browser in Ruby on Rails

I have started to learn Rails today. I am following an online tutorial. I am getting an error. In the tutorial whenever there is an error, the reason for the error is displayed in the browser. But I just get this message:
We're sorry, but something went wrong. If you are the application owner check the logs for more information.
How can I make Rails to show display the actual error like how Django displays the error when debug = True in settings.py file?
development.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
log
/usr/lib/ruby/vendor_ruby/rails/app_rails_loader.rb:39: warning: Insecure world writable dir /usr/lib/jvm/java-8-openjdk-amd64/bin in PATH, mode 040777
Array values in the parameter to `Gem.paths=` are deprecated.
Please use a String or nil.
An Array ({"GEM_PATH"=>["/var/lib/gems/2.5.0", "/home/laxman/.gem/ruby/2.5.0", "/usr/lib/x86_64-linux-gnu/rubygems-integration/2.5.0", "/usr/share/rubygems-integration/2.5.0", "/usr/share/rubygems-integration/all"]}) was passed in from bin/rails:3:in `load'
Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
/usr/lib/ruby/vendor_ruby/sprockets/digest_utils.rb:47: warning: constant ::Fixnum is deprecated
/usr/lib/ruby/vendor_ruby/sprockets/digest_utils.rb:51: warning: constant ::Bignum is deprecated
/usr/lib/ruby/vendor_ruby/sprockets/processor_utils.rb:110: warning: constant ::Fixnum is deprecated
/usr/lib/ruby/vendor_ruby/sprockets/processor_utils.rb:111: warning: constant ::Bignum is deprecated
=> Booting WEBrick
=> Rails 4.2.10 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2019-04-27 16:46:06] INFO WEBrick 1.4.2
[2019-04-27 16:46:06] INFO ruby 2.5.1 (2018-03-29) [x86_64-linux-gnu]
[2019-04-27 16:46:06] INFO WEBrick::HTTPServer#start: pid=2467 port=3000
Started GET "/" for 127.0.0.1 at 2019-04-27 16:46:10 +0530
ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
config.ru
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
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(*Rails.groups)
module Proj
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
After reviewing the full application you posted, I was able to reproduce the problem.
This issue has been reported before, in other StackOverflow posts, but I'll repeat it here:
You need to update the web-console gem to version 3.0+; in particular due to this bug fix for running the rails server in a VM/container behind a proxy.
In other words, you need to update this line in your Gemfile to:
gem 'web-console', '~> 3.0'
and then run bundle install.
On a related note, you seem to be using many outdated software versions in your project (e.g. rails version 4.2). Issues like this can usually be mitigated by keeping your dependencies up-to-date.

config/environments/development.rb command not found

I would like run a gitlab ruby on rails project.
After cloning I would like to build up the environment but there is permission problems. config/environments/development.rb get chmod +x then I use config/environments/development.rb command:
config/environments/development.rb
config/environments/development.rb: line 1: Rails.application.configure: command not found
config/environments/development.rb: line 7: config.cache_classes: command not found
config/environments/development.rb: line 10: config.eager_load: command not found
config/environments/development.rb: line 13: config.consider_all_requests_local: command not found
config/environments/development.rb: line 14: config.action_controller.perform_caching: command not found
config/environments/development.rb: line 17: config.action_mailer.raise_delivery_errors: command not found
config/environments/development.rb: line 20: config.active_support.deprecation: command not found
config/environments/development.rb: line 23: config.active_record.migration_error: command not found
config/environments/development.rb: line 28: config.assets.debug: command not found
config/environments/development.rb: line 32: config.assets.digest: command not found
config/environments/development.rb: line 37: config.assets.raise_runtime_errors: command not found
config/environments/development.rb: line 41: end: command not found
And this is the development.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
Ruby 2.3.0
Rails 4.2.6
bundle install run successfully
The project use 2.3.0 ruby
You don't run the environment file, that is for configuration purposes only.
You need to run the web server, which serves GitLab. Read docs about starting the web server, usually it's bundle exec rails s, but it would depend on the setup.
Why are you trying to run the development.rb. It is only for configuration. Settings specified here will take precedence over those in config/application.rb.
When you do a rails s i.e run your rails server, the file gets executed. The environment.rb requires the application.rb before it initializes the rails app.
If you want to just run your rails app then doing a rails s should be fine

rails not picking up new image in development

I am running into a strange issue. If i add a new image to the images folder and use it on a web page - rails is throwing an error like this.
Asset was not declared to be precompiled in production.
Add Rails.application.config.assets.precompile += %w( spinner60.gif ) to config/initializers/assets.rb and restart your server
This is all happening in development mode only. I am developing locally - and not on any server production or otherwise.
If i reboot the server on local machine - rails picks up the asset and serves it without any complains.
Anybody experience anything like this before? - No changes made to any of the environment or asset files.
Any help will be appreciated.
asset.rb =
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
# Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path
# Rails.application.config.assets.paths << Emoji.images_path
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )
and development.rb =
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
# config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end

nothing changes when making change in assets fiels

I'm trying to make a change in a css file but it seems that it is not responding to it even if a deleted that whole file, it is still loaded in the page,
I've tried to remove the assets folder from public and made
bundle exec rake assets:clean
bundle exec rake assets:precompile
but nothing changed
that's my development config file
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end

rails 3.2 and modifications on css file not reflecting until assets:precompile

I'm creating a new rails 3.2 project and everything is loading fine except the last modifications I made on css files.
If I do app/assets/stylesheets/application.css change anything on this file, I can't see the changes on the browser until I run the following command at console:
bundle exec rake assets:precompile RAILS_ENV=development
my config/environment/development.rb file.
Sample::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
end
Any help?
The problem was that I'd compiled the assets, so the rails was serving the already compiled version of these files.
In this case, all you have to do is, just delete the already generated files, like application.css and application.css.gz and you well get it working again.
Hope it helps someone.
Running bundle exec rake assets:clean solves the problem. Also if you want to manually delete these files they are present in the app's public folder inside assets.
This is kind of an old thread, but I've found that sometimes a rake assets:clean won't take care of it in Rails 4.2.1. Sometimes, you need to use a stronger verb like clobber: rake assets:clobber

Resources