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?
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.
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.
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.
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With