<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>punkracy dot com: Prototype your Rails application</title>
    <link>http://punkracy.com/articles/2007/03/20/prototype-your-rails-application</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Prototype your Rails application</title>
      <description>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&amp;#8217;t be famous &lt;a href="http://www.rubyonrails.org/screencasts"&gt;Weblog in 15 minutes&lt;/a&gt; screencast. It&amp;#8217;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.:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;lt;% for column in User.content_columns %&amp;gt;
    &amp;lt;th&amp;gt;&amp;lt;%= column.human_name %&amp;gt;&amp;lt;/th&amp;gt;
&amp;lt;% end %&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
I&amp;#8217;ll present you four tools that may look interesting for you:

	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.tonyspencer.com/2007/03/01/custom-scaffolding-for-rails/"&gt;Custom scaffold&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://masterview.org/"&gt;MasterView&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://www.streamlinedframework.org/"&gt;Streamlined&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://www.ajaxscaffold.com/"&gt;Ajax scaffold&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


But first I&amp;#8217;ll give you an idea how my sample app look. I will use one model (with one table associated of course). This is how migration file looks like:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;create_table&lt;/span&gt; &lt;span class="symbol"&gt;:users&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;t&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt;
  &lt;span class="ident"&gt;t&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;column&lt;/span&gt; &lt;span class="symbol"&gt;:first_name&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:string&lt;/span&gt;
  &lt;span class="ident"&gt;t&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;column&lt;/span&gt; &lt;span class="symbol"&gt;:last_name&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:string&lt;/span&gt;
  &lt;span class="ident"&gt;t&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;column&lt;/span&gt; &lt;span class="symbol"&gt;:address&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:text&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h2&gt;Custom scaffold&lt;/h2&gt;


You can obtain it from &lt;a href="http://www.tonyspencer.com/2007/03/01/custom-scaffolding-for-rails/"&gt;here&lt;/a&gt; and you install it just by unpacking it to &lt;code&gt;YOUR_APP/vendor/plugins/&lt;/code&gt; . After that you could check that you&amp;#8217;ve got your new generator:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;YOUR_APP$ ./script/generate
..
Installed Generators
  Plugins: custom_scaffold
..&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
Now all you need to do is to generate custom scaffold for your model (you don&amp;#8217;t need to specify controller name, but it&amp;#8217;s possible)
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;YOUR_APP$ ./script/generate custom_scaffold User admin&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
It&amp;#8217;s generating much more prettier code, 
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;lt;% for user in @users %&amp;gt;
  &amp;lt;tr&amp;gt;
    &amp;lt;td&amp;gt;&amp;lt;%= user.first_name %&amp;gt;&amp;lt;/td&amp;gt;
    &amp;lt;td&amp;gt;&amp;lt;%= user.last_name %&amp;gt;&amp;lt;/td&amp;gt;
    &amp;lt;td&amp;gt;&amp;lt;%= user.address %&amp;gt;&amp;lt;/td&amp;gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', :action =&amp;gt; 'show', :id =&amp;gt; user %&amp;gt;&amp;lt;/td&amp;gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', :action =&amp;gt; 'edit', :id =&amp;gt; user %&amp;gt;&amp;lt;/td&amp;gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Delete', :action =&amp;gt; 'destroy', :id =&amp;gt; user %&amp;gt;&amp;lt;/td&amp;gt;
  &amp;lt;/tr&amp;gt;
&amp;lt;% end %&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
but it also have some problems. It generate code in &lt;code&gt;YOUR_APP/app/views/admin/_form.rhtml&lt;/code&gt; with non existing method
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;lt;%= error_for 'user', 'first_name' %&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
So you need to delete it or add this method definition to application helper, &lt;strong&gt;something like&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/strong&gt; &lt;a href="http://snippets.dzone.com/posts/show/3403"&gt;this&lt;/a&gt;

	&lt;p&gt;You can customize templates in &lt;code&gt;YOUR_APP/vendor/plugins/custom_scaffold/generators/custom_scaffold/templates&lt;/code&gt;&lt;/p&gt;


	&lt;h2&gt;MasterView&lt;/h2&gt;


	&lt;p&gt;Authors call it template engine and you could get it from &lt;a href="http://masterview.org/"&gt;here&lt;/a&gt;. 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.&lt;/p&gt;


	&lt;h2&gt;Streamlined&lt;/h2&gt;


	&lt;p&gt;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&amp;#8217;s no contraindication to use it for general stuff.&lt;/p&gt;


	&lt;p&gt;You can watch nice screencast available at the &lt;a href="http://www.streamlinedframework.org/"&gt;framework homepage&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;Although it&amp;#8217;s looks great, it also have few problems. First of all &amp;#8211; lack of documentation and some times those doc&amp;#8217;s are out of date. Also as you see it&amp;#8217;s in early development so sometimes you could find a bug.&lt;/p&gt;


Ok. First create rails app, install plugin (version 0.0.7.1) configure your database then create model and controller:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;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 users&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
It would be available&lt;sup&gt;&lt;a href="#fn2"&gt;2&lt;/a&gt;&lt;/sup&gt; to specify model used by streamline, nevertheless pay attention to plural noun users right now.
First of all add some code to application helper
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;ApplicationHelper&lt;/span&gt;
  &lt;span class="ident"&gt;include&lt;/span&gt; &lt;span class="constant"&gt;StreamlinedHelper&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
Add code to your controller
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;UsersController&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;ApplicationController&lt;/span&gt;
  &lt;span class="ident"&gt;layout&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;streamlined&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;acts_as_streamlined&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
Now you could test your app. If you would like to use Ajax (editing, view etc.) you can meet problem in prototype library. You could find solution &lt;a href="http://streamlinedframework.org:8079/trac/ticket/16"&gt;here&lt;/a&gt;

There&amp;#8217;s also generator available. You need to install older gem (e.g. streamlined_generator-0.0.6.gem from &lt;a href="http://www.streamlinedframework.org/pages/download"&gt;Download Streamlined&lt;/a&gt; section). After that you could generate &amp;#8220;scaffold&amp;#8221; 
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;streaml$ ./script/generate streamlined user&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
and you&amp;#8217;re able to make modifications of header, menu and layout generally in the &lt;em&gt;stream/app/views/streamlined&lt;/em&gt; 

At the end I will show you quick UI configuration from the first example (version 0.0.7.1). Create file  &lt;em&gt;app/streamlined/user_ui.rb&lt;/em&gt; (if you need, create directory &lt;em&gt;app/streamlined&lt;/em&gt;). Fill that file with:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;UserAdditions&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;UserUI&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;Streamlined&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;UI&lt;/span&gt;
  &lt;span class="ident"&gt;user_columns&lt;/span&gt; &lt;span class="symbol"&gt;:exclude&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:address&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt; &lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
Refresh your view, and look at the difference. More examples here: &lt;a href="http://streamlinedframework.org:8079/trac/wiki/DeclarativeViewOptions"&gt;Declarative View Options&lt;/a&gt;

	&lt;p&gt;&lt;a href="/files/streamline1.png"&gt;&lt;img src="/files/streamline1_m.png" title="Streamlined" alt="Streamlined" /&gt;&lt;/a&gt; 
&lt;a href="/files/strealined2.png"&gt;&lt;img src="/files/strealined2_m.png" title="Edit in JavaScript window - Streamlined" alt="Edit in JavaScript window - Streamlined" /&gt;&lt;/a&gt;&lt;/p&gt;


	&lt;h2&gt;AjaxScaffold&lt;/h2&gt;


	&lt;p&gt;Last but not least &lt;a href="http://www.ajaxscaffold.com/"&gt;Ajax Scaffold Generator&lt;/a&gt;. It is available as generator or dynamic plugin. I think all of you knows that soft and if you&amp;#8217;ve never heard about it, there&amp;#8217;s a &lt;a href="http://ajaxscaffold.stikipad.com/doc/"&gt;bunch of good tutorial&lt;/a&gt; for newbies.&lt;/p&gt;


	&lt;p&gt;&lt;a href="/files/ajax_scaffold1.png"&gt;&lt;img src="/files/ajax_scaffold1_m.png" title="AjaxScaffold" alt="AjaxScaffold" /&gt;&lt;/a&gt;
&lt;a href="/files/ajax_scaffold2.png"&gt;&lt;img src="/files/ajax_scaffold2_m.png" title="Edit - AjaxScaffold" alt="Edit - AjaxScaffold" /&gt;&lt;/a&gt;&lt;/p&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; Not exactly like this. You could see only an idea.&lt;/p&gt;


	&lt;p id="fn2"&gt;&lt;sup&gt;2&lt;/sup&gt; It would be available in &lt;a href="http://www.streamlinedframework.org/articles/2007/03/22/updates-on-0-1-0"&gt;0.1.0 version&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 20 Mar 2007 13:26:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:f7c09d61-53ff-41c3-b490-228b85f3933a</guid>
      <author>Krzysztof Rączkiewicz</author>
      <link>http://punkracy.com/articles/2007/03/20/prototype-your-rails-application</link>
      <category>en</category>
      <category>ruby</category>
      <category>rails</category>
      <category>custom_scaffold</category>
      <category>masterview</category>
      <category>streamlined</category>
      <category>ajax_scaffold</category>
    </item>
  </channel>
</rss>
