Why is my Rails server not working? - ruby-on-rails

When I try to start my Rails server, using the rails server command, I get many errors. How do I fix them?
/home/action/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:205:in `parse': (<unknown>): mapping values are not allowed in this context at line 6 column 15 (Psych::SyntaxError)
from /home/action/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
from /home/action/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:153:in `parse'
from /home/action/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych.rb:129:in `load'
from /home/action/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/figaro-0.7.0/lib/figaro.rb:21:in `raw'
from /home/action/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/figaro-0.7.0/lib/figaro.rb:17:in `env'
from /home/action/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/figaro-0.7.0/lib/figaro/railtie.rb:7:in `block in <class:Railtie>'
from /home/action/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:36:in `call'
from /home/action/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /home/action/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /home/action/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /home/action/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /home/action/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/railties-4.0.2/lib/rails/application.rb:67:in `inherited'
from /home/action/workspace/learn-rails/config/application.rb:10:in `<module:LearnRails>'
from /home/action/workspace/learn-rails/config/application.rb:9:in `<top (required)>'
from /home/action/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/railties-4.0.2/lib/rails/commands.rb:74:in `require'
from /home/action/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/railties-4.0.2/lib/rails/commands.rb:74:in `block in <top (required)>'
from /home/action/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/railties-4.0.2/lib/rails/commands.rb:71:in `tap'
from /home/action/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/railties-4.0.2/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Here is application.rb file code:
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 LearnRails
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
LAST EDIT
Thank you, it was weird problem with application.yml file! Now it works like a charm!

This seems like an error with figaro gem. the Psych::SyntaxError suggests your application.yml file may be the problem.

Related

Error after upgrading mongoid 4.0.1 to 5.1.0

I upgraded Mongoid and when I run my server, I get the following error. In fact, when I run anything like console, I get the same error:
/Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/mongoid-5.1.1/lib/mongoid/railtie.rb:49:in `<class:Railtie>': uninitialized constant Mongoid::Config (NameError)
from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/mongoid-5.1.1/lib/mongoid/railtie.rb:12:in `<module:Mongoid>'
from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/mongoid-5.1.1/lib/mongoid/railtie.rb:7:in `<module:Rails>'
from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/mongoid-5.1.1/lib/mongoid/railtie.rb:6:in `<top (required)>'
from /Users/SupremeA/rails-dev-box/code/True_Numbers/config/application.rb:5:in `require'
from /Users/SupremeA/rails-dev-box/code/True_Numbers/config/application.rb:5:in `<top (required)>'
from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/railties-4.0.10/lib/rails/commands.rb:43:in `require'
from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/railties-4.0.10/lib/rails/commands.rb:43:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
It seems to be a problem with Railties but I cant seem to see how to fix it.
application.rb
require File.expand_path('../boot', __FILE__)
require "action_controller/railtie"
require "action_mailer/railtie"
require "mongoid/railtie"
#require "active_resource/railtie" # Comment this line for Rails 4.0+
require "rails/test_unit/railtie"
require "sprockets/railtie" # Uncomment this line for Rails 3.1+
#require 'rails/all'
#config.filter_parameters += [:password, :password_confirmation]
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module AppName
class Application < Rails::Application
Mongoid.logger.level = Logger::DEBUG
Moped.logger.level = Logger::DEBUG
#load vendor files
# 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
--UPDATE--
New error after removing the railties line from the application.rb
.../AppName/config/application.rb:19:in `<class:Application>': uninitialized constant AppName::Application::Moped (NameError)
from /Users/SupremeA/rails-dev-box/code/AppName/config/application.rb:17:in `<module:AppName>'
from /Users/SupremeA/rails-dev-box/code/AppName/config/application.rb:16:in `<top (required)>'
from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/railties-4.0.10/lib/rails/commands.rb:74:in `require'
from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/railties-4.0.10/lib/rails/commands.rb:74:in `block in <top (required)>'
from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/railties-4.0.10/lib/rails/commands.rb:71:in `tap'
from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/railties-4.0.10/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
I dont think you need this line in your application.rb:
require "mongoid/railtie"
Just remove it and it should work.
also remove this line:
Moped.logger.level = Logger::DEBUG
according to the mongoid docs, if you want to edit logger config, use this:
Mongoid.logger.level = Logger::DEBUG
Mongo::Logger.logger.level = Logger::DEBUG

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

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.

Rails Server Errors using Figaro

When i try to start my server after installing Figaro and adding variables to my application.yml file i get a load of errors. Can anyone explain what i need to do to fix. I've read the errors but i'm unsure.
server errors
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:205:in `parse': (<unknown>): found character that cannot start any token while scanning for the next token at line 10 column 1 (Psych::SyntaxError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:153:in `parse'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:129:in `load'
from /Library/Ruby/Gems/2.0.0/gems/figaro-0.7.0/lib/figaro.rb:21:in `raw'
from /Library/Ruby/Gems/2.0.0/gems/figaro-0.7.0/lib/figaro.rb:17:in `env'
from /Library/Ruby/Gems/2.0.0/gems/figaro-0.7.0/lib/figaro/railtie.rb:7:in `block in <class:Railtie>'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:36:in `call'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.3/lib/rails/application.rb:67:in `inherited'
from /Users/jamesrobinson/maeson/Chippy/config/application.rb:14:in `<module:Chippy>'
from /Users/jamesrobinson/maeson/Chippy/config/application.rb:13:in `<top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:74:in `require'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:74:in `block in <top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:71:in `tap'
from /Library/Ruby/Gems/2.0.0/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>'
Application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
require "active_merchant"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module Chippy
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
Application.yml
# Add application configuration variables here, as shown below.
#
# PUSHER_APP_ID: "2954"
# PUSHER_KEY: 7381a978f7dd7f9a1117
# PUSHER_SECRET: abdc3b896a0ffb85d373
# STRIPE_API_KEY: EdAvEPVEC3LuaTg5Q3z6WbDVqZlcBQ8Z
# STRIPE_PUBLIC_KEY: pk_BRgD57O8fHja9HxduJUszhef6jCyS
development:
STRIPE_SECRET_KEY: "sk_test_redactedredactedredractedWdLb"
STRIPE_PUBLISHABLE_KEY: "pk_test_redactedredactedredractedAJb"
GMAIL_USERNAME: "user#gmail.com"
GMAIL_PASSWORD: "password"
Thanks a lot
As per your config/application.yml file, you have used tabs for indentation.
YAML does not allow TAB characters (\t) for indentation. Replace all the tabs in your config/application.yml with 2 spaces indentation.
For example:
development:
STRIPE_SECRET_KEY: "sk_test_redactedredactedredractedWdLb"
STRIPE_PUBLISHABLE_KEY: "pk_test_redactedredactedredractedAJb"
GMAIL_USERNAME: "user#gmail.com"
GMAIL_PASSWORD: "password"
There was a syntax error on line 10 of my application.yml file. Changing the indentation in my Editor from tabs to spaces fixed the issue.

rails 4.1 beta upgrade 'action-view no method error'

I am trying to upgrade my rails application from rails 4.0.2 to 4.1 beta, I followed all the instructions given on http://edgeguides.rubyonrails.org/4_1_release_notes.html#action-pack-removals .
Whenever i run my application, this is the error i get
/Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.1.0.beta1/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `action_view' for # (NoMethodError)
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/jquery-rails-3.0.4/lib/jquery/rails/railtie.rb:7:in `block in '
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.1.0.beta1/lib/active_support/lazy_load_hooks.rb:36:in `call'
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.1.0.beta1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.1.0.beta1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.1.0.beta1/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.1.0.beta1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.1.0.beta1/lib/rails/application.rb:121:in `initialize'
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.1.0.beta1/lib/rails/railtie.rb:171:in `new'
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.1.0.beta1/lib/rails/railtie.rb:171:in `instance'
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.1.0.beta1/lib/rails/application.rb:90:in `inherited'
from /Users/surendra/Desktop/faces/config/application.rb:13:in `'
from /Users/surendra/Desktop/faces/config/application.rb:12:in `'
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.1.0.beta1/lib/rails/commands/commands_tasks.rb:79:in `require'
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.1.0.beta1/lib/rails/commands/commands_tasks.rb:79:in `block in server'
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.1.0.beta1/lib/rails/commands/commands_tasks.rb:76:in `tap'
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.1.0.beta1/lib/rails/commands/commands_tasks.rb:76:in `server'
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.1.0.beta1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/surendra/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.1.0.beta1/lib/rails/commands.rb:17:in `'
from bin/rails:4:in `require'
from bin/rails:4:in `'
my application.rb file is this
require File.expand_path('../boot', __FILE__)
require "action_controller/railtie"
require "rails/test_unit/railtie"
require "sprockets/railtie"
Bundler.require(:default, Rails.env)
module ElitmusFaces
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
Can you help me with this error,i would like to know where the error occured
I finally solved this problem, since I was not following rails convention in application.rb, I had to dig deeper to find where the problem is. It looks like the problem is caused by
require "action_controller/railtie"
And the error it is showing is, actionview method not found. So I just replaced that line with
require "action_view/railtie"
I got this info from
https://github.com/rails/rails/pull/7356
it seems that actionview is decoupled from actionpack, so i needed to add it myself.

Resources