Ruby on Rails on Mac not generating model - ruby-on-rails

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

Related

Does controllers get created whenever models are created?

I created model for user in ruby on rails using scaffold.
Then I got to know that when I saw controller's folder of the project I would find usercontroller.rb file created ? Does this means that whenever model is created controllers are created with it ?
It isn't the model creation that does it, it's the scaffolding.
http://guides.rubyonrails.org/v3.2.9/getting_started.html
Section 6 of that document describes what is generated during scaffolding. The scaffolding process creates a number of files, controller being one of them.
rails generate scaffold will generate a model, controller database migration, and views.
Here is a list of the generators that Rails provides:
assets
controller
generator
helper
integration_test
jbuilder
mailer
migration
model
resource
scaffold
scaffold_controller
task
The Ruby on Rails guides can provide you with additional information on the command line tools.

Could not create scaffold in rails 4.1.10

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

In what directory / folder do you install Rails Scaffold

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

Ruby On rails project without tests

I know it is not recommended but is there a way to generate/modify an existing project so it doesn't create test files when using generators such as rails generate controller NAME?
ruby script/generate controller Account --no-test-framework
Check out the API.

Add a new feature to existing rails project

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.

Resources