I'm really new to Ruby and its Rails framework and I was following a tutorial when I ran into some issues using the rails generate command. I tried using rails generate scaffold and rails generate controller but it didn't work. The full trace is this:
/usr/lib/ruby/vendor_ruby/rails/railtie/configuration.rb:95:in `method_missing': undefined method `load_defaults' for #<Rails::Application::Configuration:0x000055cdba53c180> (NoMethodError)
from /home/eric/Projects/blog/config/application.rb:12:in `<class:Application>'
from /home/eric/Projects/blog/config/application.rb:10:in `<module:Blog>'
from /home/eric/Projects/blog/config/application.rb:9:in `<top (required)>'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `require'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `preload'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from -e:1:in `<main>'
I think that the main issue is that I'm missing the 'load_defaults' method, but I couldn't find anything on how to resolve the issue. For context, I'm doing this all on a completely new rails project on Ubuntu - the only things I've done so far are rails new and bundle install.
Somewhat curiously, this issue is only popping up on new rails projects that I've created. I tried using rails generate commands on a project I had earlier and it worked. I couldn't figure out what was different between the projects though.
Any suggestions would be greatly appreciated!
Related
I'm trying to create a new app using rails-api. When I run rails-api new mynewapp I get the following:
/Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/thor-0.19.1.1/lib/thor/parser/option.rb:125:in `validate_default_type!': An option's default must match its type. (ArgumentError)
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/thor-0.19.1.1/lib/thor/parser/option.rb:111:in `validate!'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/thor-0.19.1.1/lib/thor/parser/argument.rb:24:in `initialize'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/thor-0.19.1.1/lib/thor/parser/option.rb:9:in `initialize'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/thor-0.19.1.1/lib/thor/base.rb:544:in `new'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/thor-0.19.1.1/lib/thor/base.rb:544:in `build_option'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/thor-0.19.1.1/lib/thor/base.rb:274:in `class_option'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/generators/base.rb:202:in `class_option'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/generators/app_base.rb:71:in `add_shared_options_for'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/generators/rails/app/app_generator.rb:160:in `<class:AppGenerator>'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/generators/rails/app/app_generator.rb:159:in `<module:Generators>'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/generators/rails/app/app_generator.rb:153:in `<module:Rails>'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/generators/rails/app/app_generator.rb:3:in `<top (required)>'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rails-api-0.4.0/lib/rails-api/generators/rails/app/app_generator.rb:2:in `<top (required)>'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
from /Users/sandy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rails-api-0.4.0/bin/rails-api:3:in `<top (required)>'
from /Users/sandy/.rbenv/versions/2.2.2/bin/rails-api:23:in `load'
from /Users/sandy/.rbenv/versions/2.2.2/bin/rails-api:23:in `<main>'
I get the exact same error when trying rails new mynewapp, except instead of
...gems/rails-api-0.4.0/bin/rails-api:3:in `<top (required)>'
I get
...gems/railties-4.2.4/bin/rails:9:in `<top (required)>'
And even running rails -v gives the same error.
Google was no help. Does anyone have any idea what might causing this?
If you run rails -v and get an error, your installation is probably bad. I'd try re-installing rails...
Follow this:
http://installrails.com/
It looks like thor 0.19.1.1 made a breaking change. Try changing it to 0.19.1 and see if that fixes the issue.
I have an application that is using a fork of a comfortable mexican sofa(comfy). I would like to mount mercury-rails onto comfy. The reason for this is so I can modify comfy to work with mercury.
I first added the gem for the engine into the comfy gemspec.
s.add_dependency 'mercury-rails'
ran bundle install
Then continued the guide to installing, running:
rails generate mercury:install
This gave me an error:
[WARNING] Could not load generator "generators/mercury/install/install_generator". Error: uninitialized constant Mercury::Engine.
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/mercury-rails-0.3.1/lib/generators/mercury/install/install_generator.rb:4:in `<class:InstallGenerator>'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/mercury-rails-0.3.1/lib/generators/mercury/install/install_generator.rb:3:in `<module:Generators>'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/mercury-rails-0.3.1/lib/generators/mercury/install/install_generator.rb:2:in `<module:Mercury>'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/mercury-rails-0.3.1/lib/generators/mercury/install/install_generator.rb:1:in `<top (required)>'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators.rb:280:in `block (2 levels) in lookup'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators.rb:276:in `each'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators.rb:276:in `block in lookup'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators.rb:275:in `each'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators.rb:275:in `lookup'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators.rb:137:in `find_by_namespace'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators.rb:154:in `invoke'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/commands/generate.rb:11:in `<top (required)>'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/commands.rb:48:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Now I think this is because I'm trying to install this on an engine and not an app. Which i guess engines aren't designed to do.
This error is also given if I try and run the same command from within the app.
NOTE this works when I add the gem to a standard rails app.
My questions are:
Is there any standards/documentation on mounting an engine within an engine?
If not, how would I go about doing this?
Make sure your library is also defined here: https://github.com/comfy/comfortable-mexican-sofa/blob/master/lib/comfortable_mexican_sofa/engine.rb
I am completely new to ror and am following Michael Hartl's tutorial but I keep getting an error when I get to section 1.2.5. using the rails server command. When I use this command (whilst I am in my rail app directory 'first_app') I get the following error
c:\Users\rails_projects\first_app>rails server
c:/rails_projects/first_app/config/application.rb:7:in `<top (required)>': undefined method `groups' for Rails:
Module (NoMethodError)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.11/lib/rails/comma
nds.rb:28:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.11/lib/rails/comma
nds.rb:28:in `block in <top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.11/lib/rails/comma
nds.rb:27:in `tap'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.11/lib/rails/comma
nds.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I can't figure out what went wrong, my bundle installed fine (section 1.2.4).
If your Gemfile is not set to use rails 3.1 or greater, try updating to 3.1.
Working on Mac OS X, trying to learn rails. When I type: "rails generate Scaffold User name:string email:string", I get the following error:
/Users/dnf1991/rails_projects/demo_app/config/application.rb:7:in `<top (required)>': undefined method `groups' for Rails:Module (NoMethodError)
from /Users/dnf1991/.rvm/gems/ruby-1.9.2-p290#rails3tutorial/gems/railties-3.0.9/lib/rails/commands.rb:15:in `require'
from /Users/dnf1991/.rvm/gems/ruby-1.9.2-p290#rails3tutorial/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>'
Any thoughts?
I had this exact same problem following the same guide you are. I deleted the project and re-generated, and did not follow the instructions to modify gemfile in the project to use 1.3.3 version of sql (and didn't comment out the other default inclusions) and the error went away.
Hey guys,
I clone a repo in Github: https://github.com/huacnlee/homeland/tree/
when I run the server, I got this error:
Agro:homeland Zhulin$ rails s
DEPRECATION WARNING: railtie_name is deprecated and has no effect. (called from <top (required)> at /Users/Zhulin/Desktop/RailsApps/homeland/config/application.rb:9)
/usr/local/lib/ruby/1.9.1/syck.rb:145:in `initialize': No such file or directory - /Users/Zhulin/Desktop/RailsApps/homeland/config/config.yml (Errno::ENOENT)
from /usr/local/lib/ruby/1.9.1/syck.rb:145:in `open'
from /usr/local/lib/ruby/1.9.1/syck.rb:145:in `load_file'
from /Users/Zhulin/Desktop/RailsApps/homeland/config/application.rb:48:in `<top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:28:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:28:in `block in <top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:27:in `tap'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
What should I do? And BTW where can I find simpler Rails code for learning Ruby and Rails,
Thanks
You need to set up a config.yml file in the config folder. It looks like the repo includes a config.yml.default file that you can use as a template.
It looks like you're missing your database configuration file config/database.yml for some reason. These are generated automatically by rails new <appname> so it is easy to get a replacement.
As for examples, a good reference book is always best. I like the Agile Web Development with Rails book, but there are many others.