CodeGuy
CodeGuy

Reputation: 28905

Rails create new MVC

I would like to create a model called models/thing.rb, a controller called controllers/things_controller.rb, and views called views/things/index.html.erb and views/things/hello.html.erb.

How do I do this from the rails console? I know I have to use rails generate.

Upvotes: 2

Views: 3651

Answers (1)

Pigueiras
Pigueiras

Reputation: 19356

Firstly generate the controller with two actions index and hello.

rails g controller things index hello

This command will generate the controller and the views with views/things/index.html.erb and views/things/hello.html.erb.

Then generate the model:

rails g model Thing attribute:type [...]

If you want to know more about rails generate command, you can take a look at A Guide to The Rails Command Line

Upvotes: 5

Related Questions