Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Rails, should I use the generators?

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?

like image 729
AdamT Avatar asked Oct 09 '22 07:10

AdamT


1 Answers

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.

like image 177
d11wtq Avatar answered Oct 12 '22 10:10

d11wtq