Formtastic 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.

Formtastic: Forms Made Crazy Easy for Rails Developers的更多相关文章

  1. Ruby on Rails 初次冲浪体验

    为了更好的阅读体验,欢迎訪问 作者博客原文 Rails is a web application development framework written in the Ruby language. ...

  2. Ruby On Rails 常用的精品Gem汇总

    首先需要注明一点,本文是原创的并不是从其它地方转载.所有的数据是我从 GitHub 和 RubyGems 上码下来的,数据的截取时间就是本文的发布日期. RubyGems 的下载量可以看到在用这个 g ...

  3. (转)Ruby On Rails 推荐 Gem 列表

    作者:尘缘,QQ:130775,来源:http://www.4wei.cn/archives/1002157 PHP的包管理Composer还在刚刚兴起的阶段,Ruby社区已经有很多成熟的Gem了,R ...

  4. JavaScript资源大全中文版(Awesome最新版)

    Awesome系列的JavaScript资源整理.awesome-javascript是sorrycc发起维护的 JS 资源列表,内容包括:包管理器.加载器.测试框架.运行器.QA.MVC框架和库.模 ...

  5. Top 22 Free Responsive HTML5 Admin & Dashboard Templates 2018

    Top 22 Free Responsive HTML5 Admin & Dashboard Templates 2018 May 18, 2018 Alex Ivanovs Website ...

  6. How To: Samba4 AD PDC + Windows XP, Vista and 7

    dnsmasq If you've been struggling with Samba3 domain controllers and NT4 style domains working with ...

  7. Knockout 新版应用开发教程之Observable Arrays

    假如你想到侦测和相应一个对象的改变,假如你想要侦测和响应一一组合集的改变,就要用observableArray 在许多场景都是很有用的,比如你要在UI上需要显示/编辑的一个列表数据集合,然后对集合进行 ...

  8. Git工作流指南:Gitflow工作流 Comparing Workflows

    Comparing Workflows The array of possible workflows can make it hard to know where to begin when imp ...

  9. git workflows

    https://www.atlassian.com/git/tutorials/comparing-workflows Comparing Workflows The array of possibl ...

随机推荐

  1. Delphi 中 FindWindow 和 FindWindowEx 的语法和用法

    FindWindow(lpClassName,        {窗口的类名}lpWindowName: PChar {窗口的标题}): HWND;              {返回窗口的句柄; 失败返 ...

  2. dorado-TabControl

    1.TabControl控件有点类似于.net中TableControl控件 2.常用属性 2.1 currentTab页面加载时,默认打开第几个tab,从0开始 2.2 shouMenuButton ...

  3. wpf 右下角弹出窗

    自己写的wpf 弹出框,欢迎拍砖,动画都写在了后台代码,前台代码不太重要,用了一下iconfont,具体样式我就不贴出来了,本次主要是后台代码的动画 需要有父级窗口才可以使用. 前台代码: <W ...

  4. ACTGame项目

    项目地址:https://github.com/alonecat06/ACTGame游戏地址:http://pan.baidu.com/s/1hqD3IYw 项目是一个自制单机动作游戏demo,方向是 ...

  5. map函数和reduce函数、filter函数的区别

    ①从参数方面来讲:map()函数: map()包含两个参数,第一个是参数是一个函数,第二个是序列(列表或元组).其中,函数(即map的第一个参数位置的函数)可以接收一个或多个参数.reduce()函数 ...

  6. C语言参数传递(值传递、地址传递)+二级指针

    参数传递 C语言参数传递一般分为:值传递和地址传递(本质上只有值传递) (注意:C语言中没有引用传递,C++才有引用传递,因为很多C语言环境是用C++编译器编译,使得C看起来支持引用传递,导致很多网上 ...

  7. 使用hex编码绕过主机卫士IIS版本继续注入

    本文作者:非主流 测试文件的源码如下: 我们先直接加上单引号试试: http://192.168.0.20/conn.asp?id=1%27 很好,没有报错.那我们继续,and 1=1 和and 1= ...

  8. Python中线程与互斥锁

    了解之前我们先了解一下什么是多任务? 概念: 几个不同的事件在同时运行就是多任务, 这样的话, 我们有牵扯到了真的多任务, 假的多任务; 并行: 真的多任务, 通过电脑的核数来确定 并发: 假的多任务 ...

  9. 全屏背景图的实现及background的相关属性

    今天需要做一个占满设备宽度的轮播图,这里作为demo仅展示一张图,下面分别是要操作的图片(这里做了缩放处理,实际的图比较大),以及要实现的效果图,很明显两者是不成比例的:      (图一)     ...

  10. https数字证书交换过程介绍

    文章转自:https://www.2cto.com/kf/201804/739010.html,感谢原作者的辛苦整理,讲解的很清楚,谢谢. [https数字证书交换过程介绍] 注意:该问的背景用到了非 ...