Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can generate scaffold put the controller in a namespace?

Tags:

I want to generate the scaffold in a Rails app, generating the model as usual but having the controller inside the admin namespace. Is it possible?

like image 586
pupeno Avatar asked Jun 15 '10 07:06

pupeno


People also ask

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 scaffold command in Ruby?

Scaffolding in Ruby on Rails refers to the auto generation of a simple set of a model, views and controller usually for a single table. For example: user@localhost$ ./scripts/generate scaffold users. Would create a full CRUD (create, read, update, delete) web interface for the Users table.

How to select the controller template for scaffolding services?

When the ID of a service template is specified for a controller template, after you have used the service template for scaffolding services, you will be able to select the controller template for scaffolding controllers based on the services.

What is scaffolding in DotNet?

In addition to creating projects with the dotnet CLI, such as ASP.NET MVC or Web API projects, we can generate some of the parts of these projects, such as controllers and views. We call this scaffolding: the generation of areas, controllers, views and pages with predefined code.

How to use ASPnet-codegenerator to do scaffolding?

You are now free to start using the aspnet-codegenerator command to do scaffolding. From now on, we will work with the following project, the idea is that that project has a context and a model that we will use for scaffolding: You just have to download the code in your machine, and then go to the project folder in the terminal.

How to create model class employee using scaffolding in Visual Studio?

We will create the same example which contains a model class Employee, but this time we will use scaffolding. Step 1 − Open the Visual Studio and click on File → New → Project menu option. A new Project dialog opens. Step 2 − From the left pane, select Templates → Visual C# → Web. Step 3 − In the middle pane, select ASP.NET Web Application.


2 Answers

The first time I've done it, I run

script/generate scaffold blog 

and then refactored the controller, views, etc. My prefered solution at the moment is:

script/generate scaffold admin::blog 

and then refactor the model, unit test and migration; it's less work.

If there's a better answer, I'll accept it.

like image 133
pupeno Avatar answered Oct 05 '22 08:10

pupeno


You can do this for rails < 3:

script/generate scaffold Blog title:string 

or

script/generate scaffold admin::blog title:string 

For rails > 3:

rails g scaffold Blog title:string 

or

rails g scaffold admin/blog title:string 
like image 31
ilgam Avatar answered Oct 05 '22 08:10

ilgam