5

I've encountered information that implies most experienced Rails developers don't use scaffolding. Do most experienced Rails developers even use the generators for Models, Controllers, and Migrations?

For example, as a seasoned Rails developer would I do:

rails g model Post name title content

or

rails g migration Create_Posts

and then modify it with:

  def change
    create_table :posts do |t|
    t.string :name
    t.string :title
    t.text :content

    t.timestamps
  end

and also manually create post.rb

Is using generators a best practice within Rails?

AdamT
  • 6,405
  • 10
  • 49
  • 75

3 Answers3

3

I never use the generators. I find that I just end up deleting half the stuff they create until I ultimately need to add those files/methods. In a decent text editor, it takes no time at all to create a new controller, a new model, a new template, a new spec etc.

One exception, however, is the migration generator. It's easier to use the generator in this case, since the migration has to be versioned correctly.

d11wtq
  • 34,788
  • 19
  • 120
  • 195
2

The generators are just a method to increase a time to development. You can use them if it helps you or do not use them if you don't like them.

You can create your own generators if you think that it wull improve your development process.

ceth
  • 44,198
  • 62
  • 180
  • 289
0

The generators are great to see the pattern. I am finding that as I learn more about the structure of a rails app the more I can choose what I want to do for each situation. For example I am finding that generating the models is just the way to go because of the the bits that are created (and versioned as d11wtq mentions). Then once I have the basics model to work with I can generate scaffold and use that a as a starting point for more hacking and changing.

I am looking into writing my own generators for one of the systems that has a lot of forms and at least that way I can avoid a lot of repetitive work - at least I hope so.

Hope that helps

LenW
  • 3,054
  • 1
  • 24
  • 25