What are the use cases for scaffolding in Rails? When should you use and not use it?

I am doing Agile Development with Rails 4, which uses scaffolding in most parts of the book. However, I've read on the internet that the scaffolding in Rails is actually pretty bad, but I really don't understand why. Can anyone explain this to me? Thank.

+3


source to share


2 answers


The name itself suggests using it for scaffolding . The use cases vary.

The Rails Tutorial by Michael Hartl uses it as an easy way to show you how to make Rails models work — what code is needed and where. The scaffolding demonstrates some of the basic elements of just about any Rails developer used in his applications, so at least it's a good starting point for beginners.

Once you don't start, and you can write forest-comparable code, you don't use it too often because it just doesn't fit: you end up digging up the generated code and fixing it to suit your needs for a longer than , just write what you need from scratch . Otherwise, you may accidentally reveal personal data, allow some limited actions for everyone and who knows what else. It is easier to control the code when it fills in gradually. When you lift a model, a lot of uncontrolled code appears.



However, if you're not building an application yet, but is more like researching how to build it (for example, testing various DB schemas), scaffolding is accelerated by creating an environment to create and view data in your database in a convenient way so you can test whether your ideas will work well for your needs. Once you're done, you will most likely generate a new project and implement a more polished version from scratch.

There are also exotic uses that may seem fun. With Rails, you can also create applications that will never be exposed publicly, but will rather be used internally . One such case is building a dataset for something. I personally used it to play, I got a specific game resource as a model and changed the way the JSON index is output. The resources are populated by everyone through a convenient web interface, then exported to a JSON file and placed in game assets. This saves time, I only wasted like 15-20 minutes and saved us hours of extra work of maintaining the dataset (the structure always stays true, the data can be populated by multiple people in parallel).

+2


source


I tried this on a previous version of rails. It is basically a way to create a basic full stack implementation of your application from the database to the html views and everything in between. This is only really useful if you are building a very basic application that only supports crud. I find it more useful for learning about rails than actually using it as a design approach in the real world.



This is an easy way to get your application off the ground if you just need to experiment with something.

+1


source







All Articles