简体   繁体   English

Forms 和 Rails 3 中的表单验证:构建自己的 vs Formtastic vs SimpleForm vs 其他 gem?

[英]Forms and form validation in Rails 3: build your own vs Formtastic vs SimpleForm vs other gems?

Forms offer no differentiation value for your service, but most web sites need them obviously. Forms 没有为您的服务提供差异化价值,但大多数 web 站点显然需要它们。

So far, we're building our own forms, but we would like to see how others approach forms -- especially form validation and attractive error messages -- and whether there is a more streamlined approach we're missing.到目前为止,我们正在构建我们自己的 forms,但我们想看看其他人如何处理 forms - 特别是表单验证和有吸引力的错误消息 - 以及我们是否缺少更简化的方法。

We're on Rails 3.我们在 Rails 3 上。

1) Our research has yielded Formtastic and SimpleForm as the most popular gems. 1) 我们的研究使 Formtastic 和 SimpleForm 成为最受欢迎的宝石。 Which others have you tried?你试过其他哪些?

2) What are the pros/cons for your current approach? 2)您当前方法的优点/缺点是什么?

3) We can't find demos (live working examples) of Formtastic or SimpleForm. 3) 我们找不到 Formtastic 或 SimpleForm 的演示(现场工作示例)。 Yes, we could download the code and do it ourselves, but we're wondering if there are live examples we could play with first.是的,我们可以下载代码并自己做,但我们想知道是否有我们可以先玩的实时示例。

Thanks!谢谢!

I would most definitely recommend to use either formtastic or simple-form.我绝对会推荐使用formtastic或simple-form。 While both are somewhat similar (their API is almost identical), the philosophy is a bit different.虽然两者都有些相似(它们的 API 几乎相同),但原理有点不同。

Formtastic to get started, it is supplied with a default css, it generates semantically rich and correct markup. Formtastic 开始,它提供了一个默认的 css,它生成语义丰富且正确的标记。 SimpleForm has the advantage that is extremely configurable, and will allow to configure the HTML that is generated completely. SimpleForm 具有高度可配置的优点,并且允许配置完全生成的 HTML。 And it does not come with a default css.而且它没有默认的 css。 So simple-form should be used if you are trying to implement a HTML that is defined by someone else (eg your designer).如果您尝试实现由其他人(例如您的设计师)定义的 HTML,那么应该使用简单形式。 Formtastic is just awesome if there is no specific (beforehand defined) design to follow.如果没有要遵循的特定(预先定义的)设计,Formtastic 就很棒。

With Formtastic being on the brink of their 2.0 release, it will get even more easier to extent Formtastic, I wholeheartedly recommend using Formtastic.随着 Formtastic 即将发布 2.0,扩展 Formtastic 将变得更加容易,我衷心推荐使用 Formtastic。 The amount of code you need to write to get a nice form is so much less, it is so much easier, that it seems just plain stupid to not use it.为了得到一个漂亮的表单,你需要编写的代码量要少得多,而且要容易得多,不使用它似乎很愚蠢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM