Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate a controller with all the RESTful functions

I am trying to generate a controller with all the RESTful actions stubbed. I had read at Wikibooks - Ruby on Rails that all I needed to do was to call the generator with the controller name and I would get just that. So, I ran script/generate rspec_controller Properties but got an empty controller.

Any other suggestions would be greatly appreciated.

like image 927
Barb Avatar asked Mar 23 '10 22:03

Barb


People also ask

How do you create a controller in Ruby on rails?

To generate a controller and optionally its actions, do the following: Press Ctrl twice and start typing rails g controller. Select rails g controller and press Enter . In the invoked Add New Controller dialog, specify the controller name.

How do you generate scaffold in rails?

To generate a fully working scaffold for a new object, including model, controller, views, assets, and tests, use the rails g scaffold command. Then you can run rake db:migrate to set up the database table. Then you can visit http://localhost:3000/widgets and you'll see a fully functional CRUD scaffold.

What is controller in Ruby on rails?

The Rails controller is the logical center of your application. It coordinates the interaction between the user, the views, and the model. The controller is also a home to a number of important ancillary services. It is responsible for routing external requests to internal actions.


1 Answers

I don't know about an automated way of doing it, but if you do:

script/generate controller your_model_name_in_plural new create update edit destroy index show 

All of them will be created for you

Update for Rails 4

rails g scaffold_controller Property 
like image 154
Marcos Placona Avatar answered Sep 17 '22 15:09

Marcos Placona