The options for rails is being displayed
I am new to rails. I went through a tutorial and it generated a scaffold. I tried the same as shown in the picture but could not generate it.
In the image that you posted, it seems that you didn't create your project first. Do this steps:
rails new AppName
After the app auto-bundled, go to your app directory and,
rails g scaffold Todo title:string notes:text
You can follow the following tutorial from Ruby on Rails Guides
Related
When I type into the terminal rails generate model Message, this comes up in the terminal and there is no model called Messages. What should I do? I am using El Capitan. This is the Picture
You can generate a model by
rails generate model Article title:string text:text
as copied from this page You can also generate a controller by
rails g controller controllername new create
You are getting this error because you have probably created a new rails project but you have not navigated into the folder of that project yet.
So
cd into-the-name-of-project
and then you can successfully generate models and controller there.
And if you have not created the project yet, run this command - rails new name-of-project
I am following the Rails Tutorial. It is starting to generate a scaffold. I just don't know for sure where to pit it. In a subdirectory or right at the root. My hunch is the root. i.e. JimJones$ not JimJones$/work/newapp. The apps can keep[ changing so I would imagine I would install the scaffold at the root. Any help would be greatly appreciated. Thanks, Chris
Your hunch is wrong, you should be in your /newapp directory, assuming that's the name of your app.
If you're not sure where you're at, enter pwd at the command line, and this will
print out your current location. If it ends in /newapp, you're all good.
rails generate scaffold myscaffold creates a set of MVC scaffolds called myscaffold(s), INSIDE your current app. In fact, You shouldn't be able to run rails generate scaffold unless you are inside a rails project.
Scaffolding is specific to Rails applications. First create a new Rails application using rails new appname command. Then move to the appname directory.
Then use scaffolding
rails generate scaffold test
The above command will generate a set of model, database migration for that model, controller, views, and test suites for the resource test
More info on scaffolding : http://guides.rubyonrails.org/command_line.html
You need to be in the rails app directory to use scaffold and the code generated by scaffold will be put in appropriate locations in your rails app directory e.g. model in models directory controller in controllers
I know that this error has been discussed elsewhere on the web, and this may seem like a stupid question, but I've got a very strange situation on my hands here.
I'm running on Snow Leopard, with fully updated Ruby and Rails gems. I created a new Rails project using ruby new testing, then navigated into that folder using cd ~/testing, and tried to create a basic scaffolding using ruby script/generate scaffold newtest name:string, and I got this error back:
ruby: No such file or directory -- script/generate (LoadError)
I have searched Google thoroughly and tried to implement every solution that I could, but nothing has been working. I don't understand why I have this error or how to fix it.
If you are on rails 3 then the command is:
rails generate scaffold newtest name:string
Or the slightly shorter:
rails g scaffold newtest name:string
Notice rails not ruby.
If you're on Rails 3, you need to use the rails command instead, which now does much of the scripting.
(This is according to another StackOverflow question.)
If you're using the latest version of rails then you no longer use script/generate.
In Rails 3 try using something like this instead:
cd ~/testing
rails generate scaffold Post name:string title:string content:text
You can find more info on the difference between rails 2 and rails 3 here if you like:
http://www.viget.com/extend/rails-3-generators-scaffolding/
I have recently downloaded a new project(open source),i found certain features missing like blog,forum ,chat etc.. ..so I like to add those features to the project .My problem if run rails forum it will create a new rails project but i want to add to the existing project. I have found business logic. . . .
I had created models
ruby script/generate model forum
ruby script/generate model topic
ruby script/generate model post
rake db:migrate
ruby script/generate migration add_foreign_to_topics forum_id:integer
ruby script/generate migration add_foreign_to_post topic_id:integer
rake db:migrate
Then i ran
ruby script/generate controller forum
it was asking should i overwrite or not,so i am stuck up here,i need to create a controller and view for this feature.I am following this tutorial http://net.tutsplus.com/tutorials/other/building-a-forum-from-scratch-with-ruby-on-rails/ and i have already user table etc..
As far as i can read, you are not following the tutorial, as it does a scaffold which generates the controller and models at the same time.
Either you do something like
ruby script/generate scaffold Forum title:string contents:text
and it generates the model, controller, routes and views for you. In the tutorial they use nifty_scaffold and i think it mostly improves the view.
If you create the models seperately, you need to do something like
ruby script/generate controller Forum index show create edit update new destroy
and then you will have to fill in all those actions yourself. You will also have to set your routes correctly. That is not bad and not at all difficult. But when you are starting, using the scaffold is much easier.
When I was using Rails 2, I did script/generate scaffold User to create the user model. Now I need to remove it, and I'm using Rails 3. I tried rails destroy scaffold User and rails destroy User, but these just created new rails projects named destroy. How do I do it? Thanks for reading.
Are you sure you are not running an older rails version at the time? Maybe forgot to switch to your Rails3 gemset with RVM?
It works fine here and this is the rails help output:
In addition to those, there are:
application Generate the Rails application code
destroy Undo code generated with "generate"