Formtastic: Forms Made Crazy Easy for Rails Developers

html-forms.pngFormtastic is a Rails plugin by Justin French that aims to take the headaches out of building forms in Rails views. To build it, Justin wrote down how he'd like a form creation DSL to look and then worked backwards to building the code necessary to implement that DSL. The result is a very obvious and straightforward form creation DSL.

Formtastic doesn't just make it easy to whip up basic forms, though. It has some significant advantages over similar plugins:

  • It's Rails 2.3 ready
  • It's under active development (the last update was yesterday)
  • It supports internationalization
  • It has full spec coverage
  • It can handle belongs_to, has_many, and has_and_belongs_to_many associations out of the box, rendering multi-selects and radio inputs where necessary!
  • It doesn't screw around with the existing Rails form helpers

Here's a large form example straight from Formtastic's documentation (which is pretty thorough, you'll be glad to know):

<% semantic_form_for @article do |form| %>

  <% form.inputs :name => "Basic" do %>
    <%= form.input :title %>
    <%= form.input :body %>
    <%= form.input :section %>
    <%= form.input :publication_state, :as => :radio %>
    <%= form.input :category %>
    <%= form.input :allow_comments, :label => "Allow commenting on this article" %>
  <% end %>

  <% form.inputs :name => "Advanced" do %>
    <%= form.input :keywords, :required => false, :hint => "Example: ruby, rails, forms" %>
    <%= form.input :extract, :required => false %>
    <%= form.input :description, :required => false %>
    <%= form.input :url_title, :required => false %>
  <% end %>

  <% form.inputs :name => "Author", :for => :author do |author_form| %>
    <%= author_form.input :first_name %>
    <%= author_form.input :last_name %>
  <% end %>

  <% form.buttons do %>
    <%= form.commit_button %>
  <% end %>

<% end %>

The result is a clean bundle of HTML. Groovy, right? So get reading the documentation and give it a try. It's an awesome plugin.

转载于:https://www.cnblogs.com/wangyuyu/p/3248707.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值