Ruby on Rails generators are not working - ruby-on-rails

I have a problem.
When I'm trying to generate something via rails g/rails generate controller/model/etc I got this message as an output in my terminal.
What I am doing wrong?
user#vps:/var/www/dap$ rails -v
Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
Rails 4.2.0
user#vps:/var/www/dap$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
user#vps:/var/www/dap$ ruby script/generate controller StaticPages home help about ruby: No such file or directory -- script/generate (LoadError)
user#vps:/var/www/dap$ bin/rails generate controller StaticPages home help about
Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
^C/var/lib/gems/1.9.1/gems/spring-1.3.3/lib/spring/client/run.rb:99:in `gets': Interrupt
from /var/lib/gems/1.9.1/gems/spring-1.3.3/lib/spring/client/run.rb:99:in `verify_server_version'
from /var/lib/gems/1.9.1/gems/spring-1.3.3/lib/spring/client/run.rb:56:in `run'
from /var/lib/gems/1.9.1/gems/spring-1.3.3/lib/spring/client/run.rb:37:in `warm_run'
from /var/lib/gems/1.9.1/gems/spring-1.3.3/lib/spring/client/run.rb:26:in `call'
from /var/lib/gems/1.9.1/gems/spring-1.3.3/lib/spring/client/command.rb:7:in `call'
from /var/lib/gems/1.9.1/gems/spring-1.3.3/lib/spring/client/rails.rb:23:in `call'
from /var/lib/gems/1.9.1/gems/spring-1.3.3/lib/spring/client/command.rb:7:in `call'
from /var/lib/gems/1.9.1/gems/spring-1.3.3/lib/spring/client.rb:26:in `run'
from /var/lib/gems/1.9.1/gems/spring-1.3.3/bin/spring:48:in `<top (required)>'
from /var/lib/gems/1.9.1/gems/spring-1.3.3/lib/spring/binstub.rb:11:in `load'
from /var/lib/gems/1.9.1/gems/spring-1.3.3/lib/spring/binstub.rb:11:in `<top (required)>'
from /usr/local/lib/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/lib/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from /var/www/dap/bin/spring:13:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
P.S. Added ruby and rails versions, just in a case.

Rails 4.2 requires ruby version at least 1.9.3. Prefers 2.0+
Don't use outdated version.
Also, is look like you are using system ruby. Don`t use it. Stick to rbenv or RVM

Related

rails server works but "rails console" not working

I'm working on a rails project. With command "bundle exec rails s" I can fire up a local server, however, "bundle exec rails c" throws the following errors:
/Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler/setup (LoadError)
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/commands.rb:33:in `<module:Spring>'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/commands.rb:4:in `<top (required)>'
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:77:in `preload'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:143:in `serve'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:131:in `block in run'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:125:in `loop'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:125:in `run'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
Ruby version: 2.2.2
Rails version: 4.2.5
gem version: 2.5.2
Bundler version: 1.11.2
[UPDATE]: it turns out that commenting out "spring" in Gemfile will solve this issue.
Okay, I came across this after having the same problem as poster. His update suggesting that removing spring from the Gemfile helped me get on the right track. The problem for me was that I had introduced a new environment variables, but spring didn't pick it up. When you remove spring from the Gemfile, it prevents your app from using the spring process, but it doesn't actually stop the spring process so adding it back, doing bundle install, or anything else will still leave you with the same spring process running.
To see if this is likely your issue, you can check bin/spring status and see if spring is running in the background, and if it has been running for a while.
Solution (at least for me): restart spring
bin/spring stop
rails c
Have you tried gem update --system? You may need an updated version of rubygems.
if you use rvm set the default ruby version using following, so it will pickup the correct ruby version. you probably needs to run bundle install/gem install rails -v 4.2.5 after setting the default
rvm --default 2.2.2

cannot load such file -- script/../config/boot (LoadError) after OSX Mavericks

I was doing development on a ruby on a rails application (v2.3) yesterday and decided to update my iMac to OSX Mavericks. Now, every time I try to run my application locally, I get the following error. Does anyone know whats causing this?
Run like this:
script/server -e development
Error:
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- script/../config/boot (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from script/server:2:in `<main>'
script/server (file)
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'
It was working fine before installing OSX Mavericks.
Things I Noticed:
the version of ruby installed in now 2.0 (it was v1.8.7 before)
FYI: I'm still fairly new to rails.
After Installing RVM:
Ok so I setup RVM and made sure the version of ruby (1.8.7) and rails (2.3.11) are installed and configured as the default.
Installed RVM:
curl -L https://get.rvm.io | bash -s stable --rails
Install Ruby 1.8.7:
rvm install ruby-1.8.7-p374
Set v1.8.7 as the default version:
rvm --default use 1.8.7
Install Rails v2.3.11:
gem install rails -v 2.3.11
Install all the gems from system
rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system
Now when I run my app, I get the following error: (what am I missing?)
=> Booting WEBrick...
/Users/imaginationplus/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:53:in `gem_original_require': no such file to load -- haml (MissingSourceFile)
from /Users/imaginationplus/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:53:in `require'
from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'
from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in `new_constants_in'
from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'
from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/plugins/haml/init.rb:5:in `evaluate_init_rb'
from ./script/../config/../vendor/rails/railties/lib/rails/plugin.rb:95:in `evaluate_init_rb'
from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
from ./script/../config/../vendor/rails/railties/lib/rails/plugin.rb:91:in `evaluate_init_rb'
from ./script/../config/../vendor/rails/railties/lib/rails/plugin.rb:44:in `load'
from ./script/../config/../vendor/rails/railties/lib/rails/plugin/loader.rb:33:in `load_plugins'
from ./script/../config/../vendor/rails/railties/lib/rails/plugin/loader.rb:32:in `each'
from ./script/../config/../vendor/rails/railties/lib/rails/plugin/loader.rb:32:in `load_plugins'
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:292:in `load_plugins'
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:142:in `process'
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:97:in `send'
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:97:in `run'
from /Users/imaginationplus/gitlocal/dfc_workshop/config/environment.rb:14
from /Users/imaginationplus/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:53:in `gem_original_require'
from /Users/imaginationplus/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:53:in `require'
from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'
from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in `new_constants_in'
from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'
from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/railties/lib/commands/servers/webrick.rb:59
from /Users/imaginationplus/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:53:in `gem_original_require'
from /Users/imaginationplus/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:53:in `require'
from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'
from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in `new_constants_in'
from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'
from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/railties/lib/commands/server.rb:39
from script/server:3:in `require'
from script/server:3
The main thing to understand from this issue is that you cannot rely on the OS for your ruby version or the gems that you are using within a ruby project. As you create additional ruby apps you may run into trouble with this again.
- To manage the gems use Bundler
Bundler maintains a consistent environment for each ruby applications.
- To manage the Ruby versions use rbenv or rvm
the version of ruby installed in now 2.0 (it was v1.8.7 before)
In 2.x version of Ruby, the current directory is no longer in $LOAD_PATH by default. That means that using require to load files relative to the current directory (such as script/../config/boot which expands to simply config/boot) won't work.
Alternatives are:
edit $LOAD_PATH to include the current directory by e.g. $LOAD_PATH << "."
use require_relative
Above solution was found here

Bundler fails with Rbenv

I have inherited a rails 2.3.2 application and got it to work using ruby 1.8.7 under rbenv including some old versions of other gems and software.
Now I have generated a Gemfile and try to verify it by runing any bundle comand on it, e.g. bundle check, install, etc. but any of these operations fail. I installed the rbenv bundler plugin which makes it look a little lesss severe but I still can't figure it out.
$ bundle -V
/usr/local/lib/site_ruby/1.9.1/rubygems.rb:846: Use RbConfig instead of obsolete and deprecated Config.
/usr/lib/ruby/vendor_ruby/bundler/rubygems_integration.rb:310:in `<module:Bundler>': uninitialized constant Gem::VERSION (NameError)
from /usr/lib/ruby/vendor_ruby/bundler/rubygems_integration.rb:1:in `<top (required)>'
from /usr/lib/ruby/vendor_ruby/bundler.rb:12:in `require'
from /usr/lib/ruby/vendor_ruby/bundler.rb:12:in `<top (required)>'
from /usr/bin/bundle:4:in `require'
from /usr/bin/bundle:4:in `<main>'
My bundler installation:
$ which bundle
/usr/bin/bundle
Ruby:
$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
Rbenv gives me problems too now:
$ rbenv alternatives
Skipping 1.8.7-debian, it already exists
/usr/local/lib/site_ruby/1.9.1/rubygems.rb:846: Use RbConfig instead of obsolete and deprecated Config.
Skipping 1.9.3-debian, it already exists
Isn't there supposed to be a shim for bundler? It seems that bundler is called directly.
I am lost. If anyone could help me with this I would be glad.
p.s.: I also just discovered this:
$ rbenv rehash
/usr/local/lib/site_ruby/1.9.1/rubygems.rb:846: Use RbConfig instead of obsolete and deprecated Config.
/usr/lib/ruby/vendor_ruby/bundler/rubygems_integration.rb:310:in `<module:Bundler>': uninitialized constant Gem::VERSION (NameError)
from /usr/lib/ruby/vendor_ruby/bundler/rubygems_integration.rb:1:in `<top (required)>'
from /usr/lib/ruby/vendor_ruby/bundler.rb:12:in `require'
from /usr/lib/ruby/vendor_ruby/bundler.rb:12:in `<top (required)>'
from /home/bernhard/.rbenv/plugins/bundler/etc/rbenv.d/bundler/rehash.rb:361:in `require'
from /home/bernhard/.rbenv/plugins/bundler/etc/rbenv.d/bundler/rehash.rb:361:in `require_and_patch_bundler'
from /home/bernhard/.rbenv/plugins/bundler/etc/rbenv.d/bundler/rehash.rb:427:in `<main>'
cat: /home/bernhard/.rbenv/plugins/bundler/share/rbenv/bundler/manifest.txt: No such file or directory

Having Trouble Generating a Ruby Migration

I wanted to generate a new migration for a site running Rails 2.3.14 and Ruby 1.8.7. I wrote the command
ruby script/generate migration AssetTable
Expecting the script to generate a file 20130522161112_asset_table.rb in the db/migrate directory. But I don't see this file. The output I get after running the above command is:
/var/lib/gems/1.8/gems/rails-2.3.14/lib/rails/gem_dependency.rb:81:in `add_load_paths': undefined method `requirement' for #<Rails::GemDependency:0x7ffd183eba58> (NoMethodError)
from /var/lib/gems/1.8/gems/rails-2.3.14/lib/initializer.rb:301:in `add_gem_load_paths'
from /var/lib/gems/1.8/gems/rails-2.3.14/lib/initializer.rb:301:in `each'
from /var/lib/gems/1.8/gems/rails-2.3.14/lib/initializer.rb:301:in `add_gem_load_paths'
from /var/lib/gems/1.8/gems/rails-2.3.14/lib/initializer.rb:132:in `process'
from /var/lib/gems/1.8/gems/rails-2.3.14/lib/initializer.rb:113:in `send'
from /var/lib/gems/1.8/gems/rails-2.3.14/lib/initializer.rb:113:in `run'
from /var/www/pbcore/releases/20120416101734/config/environment.rb:17
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /var/lib/gems/1.8/gems/rails-2.3.14/lib/commands/generate.rb:1
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require
Does anyone know what I'm doing wrong here?
Depending on your rubygems versions, can you try to run:
$ gem install rubygems-update -v='1.4.2'
$ gem uninstall rubygems-update -v='1.5.0'
$ update_rubygems
Seen here: Gem dependency error in rails 2.3.4 :
This is happening because you installed RubyGems that is too new for
your version of Rails. Either downgrade (and re-run update_rubygems)
or upgrade Rails to 2.3.11.

can't start script/console with Ruby 1.9 and Rails 2.3.4

I'm trying to start the console (irb) in Ruby 1.9 with Rails 2.3.4. I have two versions installed of Ruby (1.9 & 1.8.6) and I run the Ruby 1.9 by calling: rake19, ruby19, gem19...etc
And they work fine in all situations except this! it seems that its trying to load Ruby 1.8 instead! Do you know how I can change that?
Macintosh-10:favquote tammam56$ ruby19 script/console
Loading development environment (Rails 2.3.4)
/Users/tammam56/rubydev/favquote/config/../vendor/rails/railties/lib/rails/vendor_gem_source_index.rb:1:in `require': no such file to load -- rubygems (LoadError)
from /Users/tammam56/rubydev/favquote/config/../vendor/rails/railties/lib/rails/vendor_gem_source_index.rb:1
from /Users/tammam56/rubydev/favquote/config/../vendor/rails/railties/lib/rails/gem_dependency.rb:1:in `require'
from /Users/tammam56/rubydev/favquote/config/../vendor/rails/railties/lib/rails/gem_dependency.rb:1
from /Users/tammam56/rubydev/favquote/config/../vendor/rails/railties/lib/initializer.rb:10:in `require'
from /Users/tammam56/rubydev/favquote/config/../vendor/rails/railties/lib/initializer.rb:10
from /Users/tammam56/rubydev/favquote/config/boot.rb:45:in `require'
from /Users/tammam56/rubydev/favquote/config/boot.rb:45:in `load_initializer'
from /Users/tammam56/rubydev/favquote/config/boot.rb:38:in `run'
from /Users/tammam56/rubydev/favquote/config/boot.rb:11:in `boot!'
from /Users/tammam56/rubydev/favquote/config/boot.rb:110
from /Users/tammam56/rubydev/favquote/config/environment.rb:8:in `require'
from /Users/tammam56/rubydev/favquote/config/environment.rb:8
from /opt/local/lib/ruby/1.8/irb/init.rb:252:in `require'
from /opt/local/lib/ruby/1.8/irb/init.rb:252:in `load_modules'
from /opt/local/lib/ruby/1.8/irb/init.rb:250:in `each'
from /opt/local/lib/ruby/1.8/irb/init.rb:250:in `load_modules'
from /opt/local/lib/ruby/1.8/irb/init.rb:21:in `setup'
from /opt/local/lib/ruby/1.8/irb.rb:54:in `start'
from /opt/local/bin/irb:13
Thanks,
Tam
This is happening because script/console is calling irb (1.8). Assuming you have irb19 for ruby 1.9 you could do:
script/console --irb='irb19'
However there may still be problems with rails gems. If so, I'd recommend using rvm to manage your different rubys. When using rvm you will need to install gems separately for ruby 1.9 and 1.8.

Resources