Error when generating Ruby on Rails scaffold - ruby-on-rails

I am new to Ruby on Rails and I'm trying to go through a beginner's tutorial on how to produce a basic rails application. When trying to generate a scaffold, I get the following error:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:466:in routes': no >such file to load -- action_dispatch/routing/route_set (LoadError)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:519:in >block in '
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties->3.1.1/lib/rails/initializable.rb:30:in instance_exec'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties->3.1.1/lib/rails/initializable.rb:30:inrun'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties->3.1.1/lib/rails/initializable.rb:55:in block in run_initializers'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties->3.1.1/lib/rails/initializable.rb:54:ineach'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties->3.1.1/lib/rails/initializable.rb:54:in run_initializers'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties->3.1.1/lib/rails/application.rb:96:ininitialize!'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties->3.1.1/lib/rails/railtie/configurable.rb:30:in method_missing'
from C:/Users/Spi/Documents/Komodo Projects/movielib/config/environment.rb:5:in >'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties->3.1.1/lib/rails/application.rb:83:in require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties->3.1.1/lib/rails/application.rb:83:inrequire_environment!'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands.rb:22:in ><top (required)>'
from script/rails:6:inrequire'
from script/rails:6:in `'
I have the Ruby 1.9.2 and Rails 3.1.1 versions installed on a PC running windows 7 64bit. The command I'm running is the following:
rails generate scaffold Scaff_test string:title
I am running this from the command prompt while being at the directory of the rails application that I have previously created. Any help would be greatly appreciated!

The error is related to routing. As part of generating required files, it will try to update the routes.rb ( which is under config/routes.rb ).
Please check it out if the file exists and if so check the file permission of the routes.rb

Related

WKHTMLTOPDF PDF could not be generated

My rails app is working fine in many aspects but when I try to generate pdf on a production server, I get this error below. On my local computer, it's working fine. How can I go about this?.
Command Error: /home/deploy/.rbenv/versions/2.7.2/lib/ruby/2.7.0/bundler/definition.rb:495:in `validate_ruby!': Your Ruby version is 2.7.0, but your Gemfile specified 2.7.2 (Bundler::RubyVersionMismatch)
from /home/deploy/.rbenv/versions/2.7.2/lib/ruby/2.7.0/bundler/definition.rb:470:in `validate_runtime!'
from /home/deploy/.rbenv/versions/2.7.2/lib/ruby/2.7.0/bundler.rb:143:in `setup'
from /home/deploy/.rbenv/versions/2.7.2/lib/ruby/2.7.0/bundler/setup.rb:20:in `block in <top (required)>'
from /home/deploy/.rbenv/versions/2.7.2/lib/ruby/2.7.0/bundler/ui/shell.rb:136:in `with_level'
from /home/deploy/.rbenv/versions/2.7.2/lib/ruby/2.7.0/bundler/ui/shell.rb:88:in `silence'
from /home/deploy/.rbenv/versions/2.7.2/lib/ruby/2.7.0/bundler/setup.rb:20:in `<top (required)>'
from /usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
from /usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'```
Note that am using ruby 2.7.2 and I dont have ruby 2.7.0
Try to delete "bundle" folder in your app root (on production server), and run "bundle" or "bundle install" afterwards. Solved this issue for me some time ago.

Rails unable to generate model

I am trying to learn rails by following the tutorial here. However when I got to the section on creating the model and ran this command:
bin/rails generate model Article title:string text:text
I got this error:
/usr/lib/ruby/vendor_ruby/spring/application.rb:152:in `serve': undefined method `cleanup!' for ActionDispatch::Reloader:Class (NoMethodError)
from /usr/lib/ruby/vendor_ruby/spring/application.rb:131:in `block in run'
from /usr/lib/ruby/vendor_ruby/spring/application.rb:125:in `loop'
from /usr/lib/ruby/vendor_ruby/spring/application.rb:125:in `run'
from /usr/lib/ruby/vendor_ruby/spring/application/boot.rb:18:in `<top (required)>'
from /usr/local/lib/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/lib/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
This is my second go through so I know I have followed all the steps. Any idea where I might look for the solution or know what the solution is?
This really has me stuck.
Versions:
Ubuntu 16.04
ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]
gem 2.6.12
rails 5.1.0
Based on this issue, can you run spring stop and try to run your command again?
Restarting worked for me too, but I needed to do it every-time. Instead, I upgraded to to the latest version of spring (2.0.2) in my gemfile. This fixed it.

Rails 4 Error with every command "`load': no implicit conversion of nil into String" (Mac OS X 10.9)

I've just installed a fresh Ruby on Rails dev stack on my new Macbook, which runs Mac OS X 10.9 Mavericks.
Here is my stack:
Xcode command line tools
Homebrew
Rbenv
Bundler
Ruby 2.1.0
Rails 4.1.1
I ran rails new test_app to generate a first test app.
This command successfully completed, but since it, every Rails command I try in my CLI returns this kind of error message:
$ test_app > bin/rails server
/Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load': no implicit conversion of nil into String (TypeError)
from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `call'
from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
from /Users/me/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/me/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/me/Documents/[PERSONNEL]/dev/test_app/bin/spring:16:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
Same error while trying to start a console:
$ test_app > bin/rails c
/Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load': no implicit conversion of nil into String (TypeError)
from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `block in load'
from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
from /Users/me/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/me/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
The bin/rake are working partially (I can use bin/rake routes but migrations are not working).
My last try was to install XCode, but it didn't solve it.
UPDATE: the command bundle exec rake rails:update:bin as mentioned bellow solve the problem for project, but needed to be executed on every new problem.
The problem seems to be deeper.
OK I found solution.
I've cleaned my mac too. and I got same error.
rails_root/bin folder is not there?
Try below
bundle exec rake rails:update:bin
I have the same problem. Short exploration follows below.
First of all, I have [] in the root path for my application. The error during rails s command
psylone#wizard:~/ruby-rails[code]/context$ rails s
/home/psylone/.rvm/gems/ruby-2.2.0/gems/spring-1.2.0/lib/spring/client/rails.rb:30:in `load': no implicit conversion of nil into String (TypeError)
is in spring gem here: https://github.com/rails/spring/blob/master/lib/spring/client/rails.rb#L27
That's because if Dir.glob contains [] in the path argument the result will be an empty array. So it's necessary to escape [] in the path argument for Dir.glob method. I think about something like this:
# Instead of line 27 in spring/client/rails.rb
require 'shellwords'
path = Shellwords.escape(Spring.application_root_path) << "/{bin,script}/rails"
load path
After this fix I've found rails s command works fine. But rails c command still causes an error. Probably the answer has the same nature.
So, the simplest way to avoid this error - rename the root path for your application (without [] characters).

Rubymine and running rspec "rspec-core is not part of the bundle"

I am trying to run a rails app which was not created using rubymine. Its is a very different sort of app using rails engines loaded...When I try running tests, I get the following error message
Testing started at 12:29 ...
/Users/userbnamexxxx/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:214:in `block in replace_gem': rspec-core is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
from /Users/userbnamexxxx/.rbenv/versions/1.9.3-p327/bin/rspec:22:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
I edited the configuration and it does have bundle exec checkbox checked. Tests tuns fine in the console. I tried it another project which is a default bug standard rails app and its fine there... I am using rbenv for managing ruby versions....
Please help as I am really stuck and it would be nice to not use the terminal....
Add the gem
rspec-core
into your .Gemfile

Rake test fails with LoadError, looking in home directory

When I try to run "rake test" on my newly generated rails application I receive the following error
Computer:heroku user$ rake test:units
/Users/user
file doesnt exist
/Users/user/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require': cannot load such file -- /Users/user/test/unit/helpers/things_helper_test.rb (LoadError)
from /Users/user/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `block in require'
from /Users/user/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:225:in `load_dependency'
from /Users/user/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
from /Users/user/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
from /Users/user/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `each'
from /Users/user/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `block in <main>'
from /Users/user/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `select'
from /Users/user/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [/Users/user/.rvm/rubies/ruby-1.9.3-p0/b...]
Tasks: TOP => test:units
(See full trace by running task with --trace)
I am guessing that this is related to my setup somehow, as it seems as if rake is looking for the generated files in my home directory instead of the rails application directory. Could you help direct me to what I am doing wrong?
I am using Mac OS X Lion, have two installed ruby versions (1.8.7 come with lion, 1.9.3 which I am using for the application has been installed using rvm).
The application works if I run "rails s".
Update: If I create a new rails application from scratch, adding only a generated scaffold, the rake test command works. Ergo, it might be a incompatibility issue as the failing rails application was created on another computer, uploaded to heroku and then cloned from there to a new computer.
Funny story. I'd accidentally put some test code in one of the files, among other containing:
Dir.chdir("../..")
I'm guessing that when I run rake test the file got executed to load the class contained in the file, and caused problems when looking for the next file, when the current directory had suddenly changed.

Resources