Ruby on Rails - Rails commands won't run - ruby-on-rails

I am new to Rails and I'm having trouble just starting. I consistently get an error that a fork failed due to allocation problems. This is the code:
root#shotgunrides:/home/rails/rails_project# rails g model post email:string
/usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.6.2/lib/spring/application.rb:156:in `fork': Cannot allocate memory - fork(2) (Errno::ENOMEM)
from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.6.2/lib/spring/application.rb:156:in `serve'
from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.6.2/lib/spring/application.rb:131:in `block in run'
from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.6.2/lib/spring/application.rb:125:in `loop'
from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.6.2/lib/spring/application.rb:125:in `run'
from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.6.2/lib/spring/application/boot.rb:18:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'

Typically, when you see ENOMEM it means your system does not have enough memory available to accomplish whatever it was you were attempting to do. In this case it looks like your system doesn't have enough memory to handle your rails command, and just explodes.
If you could post some system specs that would be helpful, but killing running processes is pretty much the solution (aside from just adding more RAM).

Related

can't start Rails server - bunch of errors

I'm new on Ruby on Rails (actualy I'm new programming in general) and I tried to start a new server for my web app. I followed all the rules that were in the book, installed everything required (I hope I've installed it correctly), but it keeps giving me the following error:
My command ->
C:\Users\Júlia\work\demo>ruby bin/rails server
C:/Ruby30-x64/lib/ruby/3.0.0/pathname.rb:50:in `match?': invalid byte sequence in UTF-8 (ArgumentError)
from C:/Ruby30-x64/lib/ruby/3.0.0/pathname.rb:50:in `chop_basename'
from C:/Ruby30-x64/lib/ruby/3.0.0/pathname.rb:374:in `plus'
from C:/Ruby30-x64/lib/ruby/3.0.0/pathname.rb:354:in `+'
from C:/Ruby30-x64/lib/ruby/3.0.0/pathname.rb:420:in `join'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.28/lib/bundler/settings.rb:444:in `global_config_file'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.28/lib/bundler/settings.rb:93:in `initialize'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.28/lib/bundler.rb:330:in `new'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.28/lib/bundler.rb:330:in `settings'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.28/lib/bundler.rb:99:in `configured_bundle_path'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.28/lib/bundler.rb:95:in `bundle_path'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.28/lib/bundler.rb:639:in `configure_gem_home_and_path'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.28/lib/bundler.rb:81:in `configure'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.28/lib/bundler.rb:194:in `definition'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.28/lib/bundler.rb:143:in `setup'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.28/lib/bundler/setup.rb:10:in `block in <top (required)>'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.28/lib/bundler/ui/shell.rb:136:in `with_level'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.28/lib/bundler/ui/shell.rb:88:in `silence'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.28/lib/bundler/setup.rb:10:in `<top (required)>'
from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from C:/Users/Júlia/work/demo/config/boot.rb:3:in `<top (required)>'
from bin/rails:3:in `require_relative'
from bin/rails:3:in `<main>'
I'm so frustrated right now, I keep doing things apparently right but something always has to go wrong! Anyways, I hope someone will be able to help me here :(
You can follow GoRails guide to install RoR on windows it will be much easier.
Here it is: Install Ruby On Rails on Windows 10
Also after installing it you may face some other issues related to your database ( whatever database you use) like you may have installed Postgresql on windows, so when after installing it on WSL you need to kill the one running on the port that WSL will use, and similar issues, all solved across the internet

Unicorn fcntl: Errno::EPERM: Operation not permitted

I've been running Rails application on Unicorn 5.5.5 and on certain environments it throws an exception which reads
bundler: failed to load command: unicorn (/usr/local/bundle/bin/unicorn)
Errno::EPERM: Operation not permitted
/usr/local/bundle/gems/unicorn-5.5.0/lib/unicorn.rb:123:in `fcntl'
/usr/local/bundle/gems/unicorn-5.5.0/lib/unicorn.rb:123:in `block in pipe'
/usr/local/bundle/gems/unicorn-5.5.0/lib/unicorn.rb:116:in `each'
/usr/local/bundle/gems/unicorn-5.5.0/lib/unicorn.rb:116:in `pipe'
/usr/local/bundle/gems/unicorn-5.5.0/lib/unicorn/http_server.rb:126:in `start'
/usr/local/bundle/gems/unicorn-5.5.0/bin/unicorn:128:in `<top (required)>'
/usr/local/bundle/bin/unicorn:23:in `load'
/usr/local/bundle/bin/unicorn:23:in `<top (required)>
I'd like to understand what fcntl does and why is this patch added. I don't really understand the internals around IO pipes and the code described here https://github.com/defunkt/unicorn/blob/master/lib/unicorn.rb#L115 and here https://bogomips.org/unicorn-public/20180820203038.25464-1-e#80x24.org/T/
Could someone explain why this is needed and what it actually does?
We have downgraded unicorn to v5.4.1 and all is back to normal. I know that is not the solution but it helps to solve the problem for the moment.

undefined method 'load_defaults' with Rails Generate

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!

Mounting a rails engine within another rails engine

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

What’s wrong with my local Rails environment?

There is a Rails application I started a full year ago. It’s a Rails 2.3 app.
Now, someone else has made remote changes (it’s on Github, sorry, but it’s private). And I have done
sudo gem update
that is, updated all my gems, including Rails (to 3).
Realizing this, I have done
rake:freeze:edge RELEASE=2.3.8
or whatever to make this release use that version of rails, hoping this was the solution.
however, no such luck so far.
I get errors trying to start the server, AND trying to run script/console (though it’s more successful).
Note that this exact application works just fine on EngineYard.
Server:
$ script/server
=> Booting Mongrel
=> Rails 2.3.8 application starting on http://0.0.0.0:3000
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `load': syntax error on line 45, col 3: `' (ArgumentError)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `load'
from /Users/ajh/Sites/PROJECT_NAME/config/../vendor/rails/railties/lib/initializer.rb:902:in `database_configuration'
from /Users/ajh/Sites/PROJECT_NAME/config/../vendor/rails/railties/lib/initializer.rb:437:in `initialize_database'
from /Users/ajh/Sites/PROJECT_NAME/config/../vendor/rails/railties/lib/initializer.rb:141:in `process'
from /Users/ajh/Sites/PROJECT_NAME/config/../vendor/rails/railties/lib/initializer.rb:113:in `send'
from /Users/ajh/Sites/PROJECT_NAME/config/../vendor/rails/railties/lib/initializer.rb:113:in `run'
from /Users/ajh/Sites/PROJECT_NAME/config/environment.rb:11
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 /Users/ajh/Sites/PROJECT_NAME/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /Users/ajh/Sites/PROJECT_NAME/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /Users/ajh/Sites/PROJECT_NAME/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /Users/ajh/Sites/PROJECT_NAME/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
Console:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in load':ArgumentError: syntax error on line 45, col 3:rai'
And when, in console, I try to use a defined model:
#mm = MyModel.find(:all)
NameError: uninitialized constant MyModel
from /Users/ajh/Sites/PROJECT_NAME/vendor/rails/activesupport/lib/active_support/dependencies.rb:443:in load_missing_constant'
from /Users/ajh/Sites/PROJECT_NAME/vendor/rails/activesupport/lib/active_support/dependencies.rb:80:inconst_missing'
from /Users/ajh/Sites/PROJECT_NAME/vendor/rails/activesupport/lib/active_support/dependencies.rb:92:in `const_missing'
from (irb):1
I just had this error, and the problem turned out to be that I'd used a tab instead of a double-space in the database.yml file. Thought I'd mention it, in case others have the same trouble.
My database.yml had a stray end keyword. Cleaning up that file solved my problems. Thanks to Garrett for pointing me in the right direction!

Resources