Creating new models not possible - ruby-on-rails

I would like to create a new model for a Ruby on Rails application. I know that this should do:
$ ruby script/generate model Book
But it gives me:
ruby: No such file or directory -- script/generate (LoadError)
Why is that? How can I fix that? I am in my application folder.

What version of rails are you running? As far as I know it should be script/rails - but I am running rails 3.1.3
Edit: as #Jeremy bellow stated, in rails 3 and up it is script/rails - or of course, more generally, just rails
Run
ruby script/rails -h
and you should see the available commands
Run
ruby script/rails generate -h
to see what is available to generate
Alternatively, you should also just be able to run:
rails generate -h
I have never found the ruby script/rails portion to be necessary, it defaults to that automatically

If you're using Rails 3, you do it like this:
$ rails generate model Book
The way you tried is the old way. Maybe you're following an old tutorial or something.

Related

Ruby on Rails console --help not working

I have rails 5 installed via rvm, and when I type rails -h or rails generate model -h etc, I only get the standard help message :
$ rails generate model -h
Usage:
rails new APP_PATH [options] ...
I should be able to get help with all of the different rails commands on the console. Any suggestions?
Thanks.
Doh! I was in the wrong directory and/or I hadn't generated a new project yet.
It's working fine now, thanks.

Ruby on Rails: 4.2.0 differences between rails and bin/rails

So starting from Rails 4.1.x there seems to be a recommended way to use rails under the application folder. Instead of the traditional:
rails server
it is recommended by Rails official guide to use
bin/rails server
It looks like the bin/rails is referencing rails with additional stuff. What would be the additional benefits of using bin/rails compared to rails?
A second question is - I was used to use rails server, rails console, etc. rather than bin/rails server, bin/rails console. Without using bin/rails, would I lose anything (like misloading some libs, etc.)?
Thanks.
Put the following line in your bin/rails file: puts "In the bin/rails file"
Now run rails server. You'll likely see that the rails command is executing the bin/rails file.
I'm guessing the official guide suggests using bin/rails for two reasons:
Avoid using another instance of rails if your paths are not set up properly.
Speed - bin/rails seems to be a bit faster than just rails

Cucumber: web_steps.rb

I'm wasting my time here and I can't seem to figure this out..
I have used Cucumber in Rails applications before, and if I'm not mistaken, it generates the features/step_definitions/web_steps.rb file when you run rails g cucumber:install. Right?
I looked this up in a book I was using a while ago to learn Rails and it says so there aswell:
It nevertheless passes because of the features/step_definitions/web_steps.rb
file, which was generated when you ran the rails generate cucumber:install command.
However, when I run it in this application I'm trying to start working on, it does not generate it..
$ rails g cucumber:install
create config/cucumber.yml
create script/cucumber
chmod script/cucumber
create features/step_definitions
create features/support
create features/support/env.rb
exist lib/tasks
create lib/tasks/cucumber.rake
force config/database.yml
No web_steps.rb to be found. Am I losing my mind here?
Thanks.
Which version of cucumber are you using? if it is a recent version, see
https://github.com/cucumber/cucumber-rails/blob/f027440965b96b780e84e50dd47203a2838e8d7d/History.md

Why does Ruby "script/generate" return "No such file or directory"?

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'.

Why do I have problems running script/x tasks after installing rails 3 beta?

I installed rails 3 beta in my OSX Leopard. After that, I've created a rails project to test it. From inside its folder, I just can't do script/generate, or even script/server.
It returns '-bash: script/server: No such file or directory'. How could I resolve this issue?
Rails 3 has done away with script/*. Use rails server, rails generate, etc. while in your app's directory.
Run rails --help to get the full list.
In Rails 3, instead of using script/*, use rails. So instead of writing script/generate use rails g (alias of generate) and instead of script/server use rails s (alias of server).
The additional usage of port/environment is the same as in Rails 2. So you can add the port 3005 (default is 3000) with production environment as rails s -p 3005 -e production. Hope that will solve your problem.

Resources