5 min

031 RC Generators Rails Coach

    • Technology

A generator is a way of creating code from the command line. Rails has several of these built in, including generators for models, controllers, tests, helpers, scaffold (models, views, and controllers that support Rails' RESTful routing), and much more.

Generators are actually relatively simple. They are made up of two parts. The generator itself, and the generator's templates. In the Ruby on Rails source code there's an assets generator and the javascript template and stylesheet templates it uses.

I've also created a model generator for my Sandra ORM. You can find it here.

Understanding how models work, you can see how simple it is for the Rails Core Team to build in generators for other things like models, controllers, helpers, tests, assets, mailers, etc.

To see the full list of generators available in a Rails application run `rails generate` or `rails g`.

To create your own generators in your project, put them under /lib/generators or better yet, use the generator for generators like this: `rails generate generator widget` and you'll get a widget generator all set up for you in the /lib/generators folder that's ready for you to customize.

A generator is a way of creating code from the command line. Rails has several of these built in, including generators for models, controllers, tests, helpers, scaffold (models, views, and controllers that support Rails' RESTful routing), and much more.

Generators are actually relatively simple. They are made up of two parts. The generator itself, and the generator's templates. In the Ruby on Rails source code there's an assets generator and the javascript template and stylesheet templates it uses.

I've also created a model generator for my Sandra ORM. You can find it here.

Understanding how models work, you can see how simple it is for the Rails Core Team to build in generators for other things like models, controllers, helpers, tests, assets, mailers, etc.

To see the full list of generators available in a Rails application run `rails generate` or `rails g`.

To create your own generators in your project, put them under /lib/generators or better yet, use the generator for generators like this: `rails generate generator widget` and you'll get a widget generator all set up for you in the /lib/generators folder that's ready for you to customize.

5 min

Top Podcasts In Technology

nFactorial Podcast
nFactorial school
GEMBA PODCAST
Маргулан Сейсембаев
Радио-Т
Umputun, Bobuk, Gray, Ksenks, Alek.sys
Podlodka Podcast
Егор Толстой, Стас Цыганов, Екатерина Петрова и Евгений Кателла
Acquired
Ben Gilbert and David Rosenthal
Точка
Александр Плющев

More by DevChat.tv

React Native Radio
Jamon Holmgren, Robin Heinze, Mazen Chami
JavaScript Jabber
Charles M Wood
My Ruby Story
Charles M Wood
JavaScript Jabber
Charles M Wood
Adventures in Angular
Charles M Wood
Ruby Rogues
Charles M Wood