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.
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
I am trying to integrate Sidekiq with my Rails Mongoid app. I have been following the steps as outlined Here
I also have redis & mongodb running locally. However after I run bundle then when I try to start my server I get this error....
c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sidekiq-2.17.7/lib/sidekiq/rails.rb:4:in `hook_rails!': uninitialized constant ActiveRecord::Base (NameError)
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sidekiq-2.17.7/lib/sidekiq/rails.rb:16:in `block in <class:Rails>'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
from C:/Users/example/Documents/Workspace/app/config/environment.rb:5:in `<top (required)>'
My environment.rb file is as follows...
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
App::Application.initialize!
I previously had resque with redis working with mongoid in this app, so its a sidekiq issue. I don't have a database.yml file since I am using mongoid. I also added the steps for kiqstand but I am getting the same error. Unsure how to resolve?
Edit: I'm 90% sure its because Sidekiq is looking for ActiveRecord, however I removed ActiveRecord cause I'm using Mongo instead. My application.rb has...
# remove activerecord and run off of mongo only
#require 'rails/all'
#http://stackoverflow.com/a/9327651/1026266
%w(
action_controller
action_mailer
active_resource
rails/test_unit
sprockets
).each do |framework|
begin
require "#{framework}/railtie"
rescue LoadError
end
end
Now I just need to figure out how to tell sidekiq to not look for it?
Lack of ActiveRecord was the issue, looks like there was a pull request - https://github.com/mperham/sidekiq/pull/1090
But that was rejected, so I just had to add ActiveRecord to my app and add a dummy database.yml file.
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.
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.
I have a small rails app I got all gung-ho on tonight wanting to convert all the erb to haml templates. The Haml docs suggest running haml --rails /path/to/app to install it as a plugin (using the gem already installed on the system).
Unfortunately, when I attempt to start the webserver for rails, I receive the following error:
/code/src/myapp/vendor/rails/activesupport/lib/active_support/dependencies.rb:443:in `load_missing_constant': uninitialized constant Haml (NameError)
from /code/src/myapp/vendor/rails/activesupport/lib/active_support/dependencies.rb:80:in `const_missing'
from /code/src/myapp/vendor/rails/activesupport/lib/active_support/dependencies.rb:92:in `const_missing'
from /code/src/myapp/config/environment.rb:15
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:111:in `run'
from /code/src/myapp/config/environment.rb:5
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
from /code/src/myapp/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /code/src/myapp/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /code/src/myapp/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /code/src/myapp/vendor/rails/railties/lib/commands/server.rb:84
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
from ./script/server:3
It's barfing on a line in my environment file:
# Be sure to restart your server when you modify this file
RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
# Add additional load paths for your own custom dirs
config.load_paths += %W(
#{RAILS_ROOT}/lib/
)
# Specify gems that this application depends on and have them installed with rake gems:install
config.gem 'twitter'
config.gem 'newrelic_rpm'
Haml::Template.options[:format] = :html5
Haml::Template.options[:attr_wrapper] = '"'
config.plugins = [ :all ]
config.active_record.observers = :user_observer
config.time_zone = 'UTC' # "rake -D time" for all time zone names.
end
ConsumerConfig = YAML.load(File.read(Rails.root + 'config' + 'twitter-auth.yml'))
The error is on the line attempting to set some Haml options (Haml::Template.options[:format] = :html5). Installing the haml plugin with script/plugin install yields the same error, as does require haml at the top of environment.rb. Not sure if it makes a difference, but rails is frozen in vendor/rails.
This is very confusing to me, please assist if you can figure this out.
Does it work if you move the Haml::Template configuration after the Initializer block? It could be that Rails isn't loading the plugin until after the initializer is run.