Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaffolding only the view files in Rails. Possible?

Tags:

After its initial construction, I have added a couple of columns to my Books database table. As I actually want my views to reflect and show the fields related to all these new added columns I figured it'd be cheaper to just delete everything that's inside the views/books/ folder, and have some scaffold code regenerate it from the ground up. I don't want to delete either the controller or the model file, as both already contain some logic I'd like to keep. I'm fine editing those files myself on a on-need basis.

How to accomplish the task?

From https://stackoverflow.com/a/4333530/130758 I can see scaffold seems to have options for both controllers and models, but unfortunately, not for views. Am I bound to have to do this grunt work by myself? I'm aware I can just create a new git branch, delete the + model + views and regenerate all of them, copy paste the the views back into the original branch and I'm ready to go, but I'd prefer a more scientific approach, whenever possible.

Thanks

like image 337
devoured elysium Avatar asked Feb 12 '13 07:02

devoured elysium


People also ask

What does scaffolding do in Rails?

Rails scaffolding is a quick way to generate some of the major pieces of an application. If you want to create the models, views, and controllers for a new resource in a single operation, scaffolding is the tool for the job.

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.


1 Answers

I know this question is probably too old to help the person who originally asked the question, but I'd like to point out that the default scaffold generator calls the erb:scaffold generator to generate the ERB files. So, you can do:

rails g erb:scaffold Book 

This will return:

create  app/views/books create  app/views/books/index.html.erb create  app/views/books/edit.html.erb create  app/views/books/show.html.erb create  app/views/books/new.html.erb create  app/views/books/_form.html.erb 
like image 108
Jaap Haagmans Avatar answered Oct 23 '22 12:10

Jaap Haagmans