Actually,
I don’t know how fantastic Formtastic is before this afternoon, I used it to refactor my form and it’s pretty cool for me to wrap up all the massive code which I hate as always. Now every form is becoming nice.

Some relevant and useful additions about Formtastic:

SASS-stylesheets – for even more pretty styled forms in all browsers (mixins for different form layouts, etc.)
http://github.com/activestylus/formtastic-sass

TextMate-bundle for Formtastic:
http://github.com/grimen/formtastic_tmbundle

In-place editor for Formtastic:
http://github.com/rubymood/jintastic

Client-side validations that is compatible with Formtastic markup:
http://github.com/grimen/validatious-on-rails

最近花了一些时间改造公司的网站(EQV2),这个网站是一个偏重内容和设计的信息类主站,并没有太多功能性的要求,所以在使用Ruby on Rails开发这个网站的时候,尝试了一些之前涉及不多的技术。最初这个网站利用Radiant(RoR的开源CMS系统)搭建,考虑到没有专门的技术人员来管理和研究Radiant,而且和我们自己的系统平台的集成也会有些麻烦,最终决定放弃这把牛刀,仅仅做一个简单而且结构清晰的网站就OK。

我简单列一下这次改造过程中的一些比较典型的处理方法和技术:

* Formtastic + nifty_scaffold
用这两招可以方便的产生后台的CRUD管理部分,不知道为什么我第一反应没有使用ActiveScaffold,可能是从Rails2.3+以后Denny老说使用起来有问题有冲突,我就本能的绕开它了。
参考: http://asciicasts.com/episodes/184-formtastic-part-1

* feedzirra + whenever
feedzirra是一个方便易用的RSS分析器,很不错,结合whenever就可以自动更新源RSS,在我们的系统中我用它们更新Blog中的内容到网站上面来。
参考: http://github.com/pauldix/feedzirra
http://github.com/javan/whenever/

* cas
7哥搭建了一个idp_cas的server,我就结合这个做了一个单点登录的控制,用来对后台内容管理做权限控制。这个方案很轻量级,避免了直接集成复杂的idp用户验证系统。

* Routing
此次最想突出介绍的是ROR的Routing机制,强大的Routing可以将URL改写成任何形式,以适应SEO的需要,同时也可以做坏链的容错处理。很好很强大,就是不知道效率如何,这个有待进一步熟悉。

* caches_page
由于本次改造过程中主要涉及内容性质的View,所以我只进行了Page Cache,Rails的Cache方法也很简单易用,我稍后会做一个较为详细的总结,讨论一下各种Cache的问题。

此次改造的重点是网站结构和UI/UE的设计,Noah和Buzz主要负责这方面的工作,正因为他们出色的工作成果才使得EQV2顺利按期交付。

I’ve been working on EQ portal during these days, I wanna share a useful gem which I used, it is called Formtastic. it’s a nice way to create form via formtastic, so the finial form is something like:

1
2
3
4
5
6
7
8
9
10
11
<% semantic_form_for @landing, :url=>admin_landings_path do |form| %>
  <p>
    <% form.inputs do %>
      <%= form.input :title, :label => 'Title' %>
      <%= form.input :url_slug, :label => 'Url slug' %>
      <%= form.input :meta, :label => 'Meta' %>
      <%= form.input :content, :label => 'Content' %>
    <% end %>
  </p>
  <p><%= form.buttons %></p>
<% end %>

Then it will generate HTML like this:

1
2
3
4
5
6
7
8
9
10
11
12
<form action="/admin/landings" class="formtastic landing" id="new_landing" method="post"><div style="margin:0;padding:0;display:inline"><input name="authenticity_token" type="hidden" value="EC9WF1oK80Iq6X4NegSkBfVx5gLiYWvBEd7VeNKWHio=" /></div>
  <p>
    <fieldset class="inputs"><ol>
      <li class="string required" id="landing_title_input"><label for="landing_title">Title<abbr title="required">*</abbr></label><input id="landing_title" maxlength="255" name="landing[title]" size="30" type="text" /></li>
      <li class="string required" id="landing_url_slug_input"><label for="landing_url_slug">Url slug<abbr title="required">*</abbr></label><input id="landing_url_slug" maxlength="255" name="landing[url_slug]" size="30" type="text" /></li>
      <li class="text required" id="landing_meta_input"><label for="landing_meta">Meta<abbr title="required">*</abbr></label><textarea cols="40" id="landing_meta" name="landing[meta]" rows="20"></textarea></li>
      <li class="text required" id="landing_content_input"><label for="landing_content">Content<abbr title="required">*</abbr></label><textarea cols="40" id="landing_content" name="landing[content]" rows="20"></textarea></li>

    </ol></fieldset>
  </p>
  <p><fieldset class="buttons"><ol><li class="commit"><input class="create" id="landing_submit" name="commit" type="submit" value="Create Landing" /></li></ol></fieldset></p>
</form>

Also, it can be configured well in display style(not try yet), as well as working with this validation plugin

There is a more detailed Doc at: http://rdoc.info/rdoc/justinfrench/formtastic/blob/35eadf9a0f3e30101993419c3dd3327fb2fdd0b6/Formtastic/SemanticFormBuilder.html.  And samples at: http://asciicasts.com/episodes/184-formtastic-part-1

Enjoy it.

© 2011 Refactoring Thoughts Suffusion theme by Sayontan Sinha
普人特福的博客cnzz&51la for wordpress,cnzz for wordpress,51la for wordpress