LeanScaffold
LeanScaffold can be installed as a plugin (recommended your first time) or as a gem. It allows you to generate a scaffold much like the regular Rails scaffold generator… but leaner… and, well – cooler.
Features
- Generates a low fat model, controller and set of views
- Generates a migration and form fields (including the attributes you pass in)
- Doesn’t include all that other jazz you don’t need (particularly in the controller)
- Generates a fixture and functional and unit tests (like the normal Rails scaffold generator)
- Automates the use of a spinner image that swaps itself in place of a form’s submit button upon submission
Usage
script/generate lean_scaffold widget name:string description:text
Attributes and their data types are optional, but will result in populated migrations and generated form fields if provided.
Prerequisites
- restful_authentication (just becuase it adds ‘before_filter :login_required’ to the controllers, which you can manually remove)
- Grab a spinner image from http://www.ajaxload.info, name it spinner.gif and drop it in public/images. This image will appear in place of the submit button when you submit a form.
- Add the following JavaScript to your app:
function spin(){ Element.toggle(‘processing’); Element.toggle(‘submit’); }
After setup
- Add some CSS for the spinner image that appears when you submit a form, just align the image – pretty straightforward.
Assumptions
What’s a Rails plugin without some assumptions? Well you may notice that this plugin has made some judgement calls for you. For example, links such as “New Widget” and headers such as “Listing Widgets” have been omitted. I use other frameworks/helpers that auto-populate these things, so I intentionally left them out of this generator since we don’t want to add stuff to our views that we just have to immediately strip out do we?
Using the Gem
- Place the methods located in lib/lean_scaffold_helper.rb in a helper in your application.
- You do not need to have the plugin installed.
Generated tests
Currently you’ll get (virtually) the same fixtures and functional and unit tests as you would from the normal scaffold generator. Later I’d like to move this to Shoulda and Factory Girl.
License
(The MIT License)
Copyright © 2009 Kenny Johnston
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.