Rails 3 compatible generators for DataMapper, Haml, Factory-girl, Authlogic, Mongomapper, and Mongoid
This is a fork from the indirect rails3-generators at github.com/indirect/rails3-generators Unlike these generators, this repository will not be as general or compatible as the source, but will speed up scaffolding a lot when some conventions are used. The main changes are:
-
many strings from the scaffold command with haml now link to helper methods, in stead of being just stings
-
The title is now done using the title helper method as used by Ryan Bates
To fully use the features of these generators you should have the following:
-
A yield :title somewhere in your layout
-
a shared/_error_messages partial (A default is provided)
-
Add the default translations given in this README to your config/locales/en.yml file
-
Add the generated translations after each scaffold
Also soon I will add the used helpers to rails which can be overwritten in you own helpers. These are
-
title
-
new_text
-
edit_text
-
show_text
-
destroy_text
-
index_text
-
update_button_text
-
create_button_text
-
boolean_text
Now you can replace all your scaffolding links with images if you wish without a blink. Assumptions for this repo:
-
Your tables/columns are in English
-
You will use internationalisation (Easy to get rid of, but built-in by default)
The following translation strings are used. Change it using your own helper, or in the translation file:
Errors title: one: one error prohibited this record from being saved other: "{{count}} errors prohibited this record from being saved" boolean true: "yes" boolean false: "no" New: New Edit: Edit Show: Show Back: Back Delete: Delete Create: Create Save: Save Are you sure: Are you sure?
In the standard behaviour a namespace kind of thing can be achieved by using a scaffold statement like:
rails g scaffold admin/modelname attribute:attribute_type
This however does not in a required result. In my opinion controllers and views should support namespaces, but models not. An ugly temporary fix is the support for a namespace option. This can be used for example:
rails g scaffold Page name:string parent_id:integer --namespace=admin
In this case the views will support links for namespaces. An action list for myself for this case:
-
move app/views/pages => app/views/admin/pages
-
move app/controllers/pages_controller.rb to app/controllers/admin/
-
Open the controller file (app/controllers/admin/pages_controller.rb)
- Add Admin
-
before the class definitions on the first line
-
make the redirect to [:admin, @page] in the create/update actions
-
make the redirect to admin_pages_url in the destroy action
-
Ensure the proper routes
namespace :admin do resources :pages end
-
And don’t forget to migrate :)
Fork the repo, add a generator, send a pull request. Pretty simple.
DataMapper generators: Jose Valim
Haml: Paul Barry, Anuj Dutta, Louis T
Factory Girl: Paul Barry
Authlogic: Jeff Tucker
MongoMapper: Jai-Gouk Kim
Machinist: Darcy Laycock
Mongoid: Guillaume Belleguic