I am learning Ruby on Rails using a book I picked up called "Head First Rails" I am in the first chapter and it tells me to create my CRUD procedures using the following command:
ruby script/generate scaffold ticket name:string seat_id_seq:string address:text price_paid:decimal email_address:string
the error I am getting is:
ruby: No such file or directory -- script/generate (LoadError)
Can someone please explain what I am doing wrong. I am not new to development, I am a professional C# developer trying to learn Ruby on Rails.
Are you running that in your application directory? The scaffold command needs to be executed in your application directory in order to find script/generate.
try simply "./script/generate ..." in your project directory
This question is old, but for anyone who is having problems with "Head First Rails" first edition (which is the only one available at this time), it was written for rails 2. So most of the commands, like script/generate, have been replaced by new ones in Rails 3.
I suggest using "Agile Web Development with Rails" book.
Related
I study Rails with the book "Head First Rails"
steps are:
to create my app with the command "rails new tickets"
run server with "ruby script/server"
"ruby script/generate scaffold ..."
But there is no script folder in the project and I get an error "ruby: No such file or directory -- script/generate (LoadError)"
I've found that I need to use "ruby s" to start the server.
But how can I run script/generate?
Is it a new style of generating folders in the rails project and there is no more script folder? Or did I smth wrong?
I have ruby version 2.4.4 and rails 5.2.1
nowadays it is used rails instead of ruby script/, so try rails server or rails generate scaffold
I am writing a small blog application using Rails. I am using Aptana Studio.
When I try to execute:
ruby script/generate scaffold post title:string body:text
from either Aptana Studio or going to the project folder and executing it from the shell, I get this error:
c:\Ruby200\bin\ruby.exe: No such file or directory -- script/generate (LoadError
)
I think you are meaning to do rails generate?
First create a new Rails app:
rails new random_app
cd random_app
rails generate scaffold post title:string body:text
When you "ruby" something, it looks for a file to execute.
Rails is the framework for abstraction and scaffolding.
See "Why does Ruby "script/generate" return "No such file or directory"?".
Rails 3 is the problem. Since Rails 3, all of the "script/whatever" commands have been replaced with "rails whatever".
So now you want rails generate ... or rails server instead.
I am looking at rails plugins to help me modularize my application. I have some basic questions that I am confused about.
Can a rails plugin have its own DB? My application is very little traffic, for internal use, so I am fine with the idea of separate sqlite DB's for each plugin. When I do a "rails plugin new" even if I use --full, there is no database.yml generated. If I create one and do a rake db:create, no sqlite db is created.
Is there a good tutorial available for creating a rails plugin with rails 3.2? Most I find are older and use the enginex gem which I think is now built into rails.
Can you run your plugin as a standalone app for testing, i.e. using WEBrick? When I run "rails server" in my plugin directory, it just says "Error: Command not recognized".
I guess that's it, I am just confused on how to begin.
Creating Migrations
The Rails Guide "Getting Started with Engines" instructs you to use 'rails g model post' from the root directory for your engine.
Getting Started with Engines
If you do this, it will create the db/migrate folder for you with the migration inside of it.
$ rails g model post
invoke active_record
create db/migrate/20120517184738_create_my_engine_posts.rb
create app/models/my_engine/post.rb
invoke test_unit
create test/unit/my_engine/post_test.rb
create test/fixtures/my_engine/posts.yml
You can also generate migrations directly just the same, just as you do with a Rails app.
$ rails g migration AddMyEngineTable
invoke active_record
create db/migrate/20120517185241_add_my_engine_table.rb
Running Rails Server
The Rails Guide also states to run 'rails s' from test/dummy, not from the root of your engine directory.
I see that from an ASCIICast on the subject which covered Rails 3.1 RC5 that you used to be able to run 'rails s' from the root directory of your engine/gem. This is no longer the case.
From the Rails issue posted on Github three months ago it appears that they needed to keep the scope of the engine separate from the scope of the dummy app.
Issue #4894: Mountable Engines Rails File
In short run from the engine root:
test/dummy/script/rails s
Trying to follow the "Ruby on Rails 3 Tutorial" and running rails s, getting the following error:
[path]\config.ru:1 in 'require': no such file to load -- fake_app
I've got the location of fake_app.rb in the PATH (which I presume is what rails/rack is trying to find)
Contents of config.ru are the default generated:
require "fake_app"
run Rack::Test::FakeApp
I am running rails 3.0.8 and Windows 7
Thanks for helping this complete novice out!
Did you generate this with rails new [appname] command? A default Rails 3.0 config.ru file should look more like this:
require ::File.expand_path('../config/environment', __FILE__)
run ApplicationName::Application
If all you've done at this point is install Ruby and Rails, I'd re-run the generator to get something that works.
Also, since you're on Windows, I wanted to recommend Rails Installer for your environment installation and setup. It mitigates a lot of the startup pain.
This is probably the tutorial you are speaking of, but I also highly recommend Michael Hartl's Ruby on Rails Tutorial for a solid introduction to Rails 3. The section about generating your first application may be handy in this situation.
I am having trouble using script/generate. I am following the tree based navigation tutorial, which says to use script/plugin install git://github.com/rails/acts_as_tree.git or script/generate nifty_layout.
I keep getting:
No such file or directory -- script/plugin
I've tried these variations:
script/generate nifty_layout
rails generate nifty_layout
ruby script/generate nifty_layout
ruby generate nifty_layout
and they all tell me:
-bash: script/generate: No such file or directory
Am I missing something? Total ruby nuby here and I just can't seem to find an answer.
edit: rails 3 on Mac OS X 10.6
Rails 3 is your problem (or rather the cause of). Since rails 3 all of the "script/whatever" commands have been replaced with "rails whatever".
So now you want "rails generate ..." or "rails server" instead.
Be sure to watch version numbers or post dates when looking at tutorials :)
linkage:
Missing script/generate in Rails 3
There is a LOT of out-of-date information on the interwebs for Rails now as a result of it evolving quickly and being so popular. I use the Ruby on Rails Guides as my first stop for information as those pages seem to be the most current.
The rails generate info seems current.
you may try a couple things, first, make sure since you are using rails 3 that you have run 'bundle install'. depending on how you installed rails and which version of bundler you are using, it may not be finding your rails binary to execute the rails generate .. so you may try prefixing it with bundle exec rails g but that is deprecated and you should get a warning if you call it. Also, make sure you are following ryan's instructions for rails 3 (and run bundle install once you add to the gemfile) on his library: https://github.com/ryanb/nifty-generators
As a shortcut to rails server, you can use 'rails s'. Similarly for the console, 'rails c'.