Trouble with new rails app - ruby-on-rails

I have just created a new rails app (on the CL, using rails new), I am on 4.2.6, but it seems like before I can do anything to the app that i've hit errors.
first...
/config/environments/development.rb:53:in `block in <top (required)>':
uninitialized constant ActiveSupport::EventedFileUpdateChecker (NameError)
then once I comment that out...
/config/initializers/new_framework_defaults.rb:15:in `<top (required)>':
undefined method `to_time_preserves_timezone=' for ActiveSupport:Module (NoMethodError)
and once that is commented out...
/config/initializers/new_framework_defaults.rb:21:in `<top (required)>':
undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module (NoMethodError)
and lastly...
.gem/ruby/2.2.3/gems/actionmailer-4.2.5/lib/action_mailer/base.rb:569:in `method_missing':
undefined method `perform_caching=' for ActionMailer::Base:Class (NoMethodError)
everything I can turn up on Google suggests these are Rails 5 related things. I'm not sure how to get around them, or how to create an app that is still specific to 4.2.6.

If still you want to use Rails 5 comment the below line in development.rb file:
config.action_mailer.perform_caching = false
And after doing that you may get:
ActionView::Template::Error (couldn't find file 'ation_cable' with type 'application/javascript'
Then remove = from //= require action_cable in your cable.js file.

tl;dr: Re-create your Rails project, providing the specific Rails version.
To elaborate on Peter's answer: often this error occurs because you have a newer version of Rails installed than the one called for in your .railsrc or template.rb.
If this is the case, when you run rails new my_new_app, the newest version is used by default for the earlier steps of the process, but then once the template/railsrc version is installed, latter steps use this version. This causes compatibility issues.
You can verify that this is your problem by comparing the output of rails -v (in the directory where you called rails new) with what's in your .railsrc or template.rb. If they are different, there is an easy fix:
Recreate your Rails app, specifying the same Rails version from your .railsrc or template.rb in the command line call:
rails _4.2.5.1_ new my_new_app

Related

ruby gem issue uninitialized constant

Ok I'm not a pro at creating gems, but I tried my best and created this gem https://rubygems.org/gems/webpack_native/versions/0.2.0
This gem has generators and if I use it from the local folder (meaning the gem folder is in my computer) it works fine, if I type rails g in terminal it shows me the generators including my gem's generators
But using it from rubygems always give me an error uninitialized constant WebpackNative:
/home/mody/.rvm/gems/ruby-2.7.0#myapp/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/active_support.rb:80:in `block in load_missing_constant': uninitialized constant WebpackNative (NameError)
any thoughts on this?
I'm not sure how this happen but I get it to work after I installed devise gem and run
rails g
the output of the available generators shows up including my gem, and the generator itself is working.

Ruby 'requires' are throwing NoMethodError's, stack trace shows Unix paths on a Windows machine

Trying to run a ruby script, but it's failing on the 'require' statements, throwing a strange error:
Code:
require "rubygems"
require "bundler/setup"
require_relative "plugins/pivotal_rabbitmq_plugin/pivotal_rabbitmq_plugin.rb"
require "newrelic_plugin"
module PivotalAgent
NewRelic::Plugin::Config.config_file=File.dirname(__FILE__) + "/config/newrelic_plugin.yml"
NewRelic::Plugin::Run.setup_and_run
end
Command:
ruby pivotal_agent.rb
Error:
/usr/share/rubygems/rubygems/path_support.rb:78:in `path=': undefined method `+' for nil:NilClass (NoMethodError)
from /usr/share/rubygems/rubygems/path_support.rb:34:in `initialize'
from /usr/share/rubygems/rubygems.rb:325:in `new'
from /usr/share/rubygems/rubygems.rb:325:in `paths'
from /usr/share/rubygems/rubygems.rb:348:in `path'
from /usr/share/rubygems/rubygems/specification.rb:872:in `dirs'
from /usr/share/rubygems/rubygems/specification.rb:750:in `stubs'
from /usr/share/rubygems/rubygems/specification.rb:938:in `find_inactive_by_path'
from /usr/share/rubygems/rubygems.rb:186:in `try_activate'
from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:126:in `rescue in require'
from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:39:in `require'
from pivotal_agent.rb:2:in `<main>'
Any ideas what might be causing that? My initial hunch is that it has something to do with the file paths it's looking at being formatted for Unix while this is running on a Windows machine, but I've added Ruby to PATH, so I don't know why it would be looking there rather than where Ruby is actually installed (C:\Ruby22-x64).
EDIT: To clarify, the first require (for 'rubygems') doesn't throw an error, but both the other requires and the require_relative all throw a similar one.
Not 100% sure why, but removing the 'ruby' from the start of the command fixed it. So just running
my_script.rb
works fine, but running
ruby my_script.rb
gives the above stack.

rails console gives method_missing, undefined

I am following a Rails tutorial and have to run rails console. I never had a issue with it before but now it doesn't run.
Here's the error.
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.11/lib/rails/railtie/configuration.rb:85:in `method_missing': undefined method `generators' for
#<Rails::Railtie::Configuration:0x007ffc41d4a9a0> (NoMethodError)
from /Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/rspec-rails-2.0.0.beta.18/lib/rspec-rails.rb:4:in `<class:Railtie>'
I noticed that your rspec gem is the same version as listed here: "rails generate rspec:install" seems to be failing
Maybe that will help.

undefined local variable or method `config' for main:Object - rails

When I run the rails application, I get the following error:
undefined local variable or method "config" for main:Object
How can I resolve it?
My guess is that you found some code examples from an older version of rails, which called for you to place a config.gem * in your environment.rb file. To fix this add the gem requirement to your gemfile.
in your enviroment.rb file, cut any line starting with config and paste into your production.rb/development.rb/test.rb instead.
This is what worked for me when I had a similar problem.
I had this problem when an application had been upgraded from Rails 2 to Rails 3. It worked in development but I got this error when running in production mode for the first time because config/environments/production.rb contained Rails 2-style lines such as:
config.cache_classes = true
..which needed converting to Rails 3-style:
<<NameOfYourApp>>::Application.configure do
config.cache_classes = true
end

`method_missing': undefined local variable or method `authentication_keys' error when installing devise

I'm trying to get Devise up and running. I'm using devise 1.0.10 and rails 2.3.8, on an otherwise pretty clean hostingrails install.
When I run ruby script/generate devise_install
I get the following error message. Has anyone seen this before. Any ideas how to proceed with the install? I searched around and hit a wall.
Thanks, Tim
ruby script/generate devise_install
/home/p7017r10/appname/config/environment.rb:4: warning: already initialized constant RAILS_ENV
/usr/local/rvm/gems/ruby-1.8.6-p369/gems/activerecord-2.3.8/lib/active_record/base.rb:1994:in method_missing': undefined local variable or methodauthentication_keys' for # (NameError)
from /usr/local/rvm/gems/ruby-1.8.6-p369/gems/devise-1.0.5/lib/devise/models/validatable.rb:18:in included'
from /usr/local/rvm/gems/ruby-1.8.6-p369/gems/devise-1.0.5/lib/devise/models/validatable.rb:16:inclass_eval'
from /usr/local/rvm/gems/ruby-1.8.6-p369/gems/devise-1.0.5/lib/devise/models/validatable.rb:16:in included'
from /usr/local/rvm/gems/ruby-1.8.6-p369/gems/devise-1.0.5/lib/devise/models.rb:66:ininclude'
from /usr/local/rvm/gems/ruby-1.8.6-p369/gems/devise-1.0.5/lib/devise/models.rb:66:in devise'
from /usr/local/rvm/gems/ruby-1.8.6-p369/gems/devise-1.0.5/lib/devise/models.rb:65:ineach'
from /usr/local/rvm/gems/ruby-1.8.6-p369/gems/devise-1.0.5/lib/devise/models.rb:65:in devise'
from /usr/local/rvm/gems/ruby-1.8.6-p369/gems/devise-1.0.5/lib/devise/orm/active_record.rb:24:inincluded_modules_hook'
... 37 levels...
from /usr/local/rvm/gems/ruby-1.8.6-p369/gems/rails-2.3.8/lib/commands/generate.rb:1
from /usr/local/rvm/rubies/ruby-1.8.6-p369/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require'
from /usr/local/rvm/rubies/ruby-1.8.6-p369/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from script/generate:3
check the devise group on google groups
http://groups.google.com/group/plataformatec-devise
that's the better forum to ask this question
I guess you should look into initializers/devise.rb. There are some instructions on setting those keys. Plus, please refer to http://asciicasts.com/episodes/210-customizing-devise, http://blog.plataformatec.com.br/tag/subdomain/.
I didn't use devise with RoR 2.3.x, only with 3.0.x. That could be the difference.
Hope that helps. Let us know :)

Resources