Prototype your Rails application
Posted by Krzysztof Rączkiewicz Tue, 20 Mar 2007 12:26:00 GMT
Today I want to show you some piece of software that will help you quickly prototype your Rails application. We all know the scaffold mechanism. Without it there wouldn’t be famous Weblog in 15 minutes screencast. It’s really nice for beginning or if you what to quickly show someone (or to yourself) the idea of your application. But scaffold generate not very beautiful code. E.g.:<% for column in User.content_columns %>
<th><%= column.human_name %></th>
<% end %>create_table :users do |t|
t.column :first_name, :string
t.column :last_name, :string
t.column :address, :text
endCustom scaffold
You can obtain it from here and you install it just by unpacking it toYOUR_APP/vendor/plugins/ . After that you could check that you’ve got your new generator:
YOUR_APP$ ./script/generate
..
Installed Generators
Plugins: custom_scaffold
..YOUR_APP$ ./script/generate custom_scaffold User admin<% for user in @users %>
<tr>
<td><%= user.first_name %></td>
<td><%= user.last_name %></td>
<td><%= user.address %></td>
<td><%= link_to 'Show', :action => 'show', :id => user %></td>
<td><%= link_to 'Edit', :action => 'edit', :id => user %></td>
<td><%= link_to 'Delete', :action => 'destroy', :id => user %></td>
</tr>
<% end %>YOUR_APP/app/views/admin/_form.rhtml with non existing method
<%= error_for 'user', 'first_name' %>You can customize templates in YOUR_APP/vendor/plugins/custom_scaffold/generators/custom_scaffold/templates
MasterView
Authors call it template engine and you could get it from here. It is distributed as gem or plugin and installation is described on the main page. You can also watch screencast presenting MasterView power, so I will not focus on it.
Streamlined
This one is really nice and quite powerful. With help of this plugin you can generate nice, powerful including JavaScript interface for you ActiveRecord models. At the beginning, it was used mainly for administrative purpose, but there’s no contraindication to use it for general stuff.
You can watch nice screencast available at the framework homepage
Although it’s looks great, it also have few problems. First of all – lack of documentation and some times those doc’s are out of date. Also as you see it’s in early development so sometimes you could find a bug.
Ok. First create rails app, install plugin (version 0.0.7.1) configure your database then create model and controller:dev$ rails streaml
dev$ cd streaml
dev$ ./script/plugin install http://svn.streamlinedframework.org/edge/streamlined
[CONFIGURE_DB]
streaml$ ./script/generate model User
streaml$ ./script/generate controller usersmodule ApplicationHelper
include StreamlinedHelper
endclass UsersController < ApplicationController
layout 'streamlined'
acts_as_streamlined
endstreaml$ ./script/generate streamlined usermodule UserAdditions
end
class UserUI < Streamlined::UI
user_columns :exclude => [:address]
end AjaxScaffold
Last but not least Ajax Scaffold Generator. It is available as generator or dynamic plugin. I think all of you knows that soft and if you’ve never heard about it, there’s a bunch of good tutorial for newbies.
1 Not exactly like this. You could see only an idea.
2 It would be available in 0.1.0 version




