Rails simple_form is not worth the trouble.

hardywu · 2013年11月18日 · 最后由 zhangyanan 回复于 2013年11月19日 · 3791 次阅读

从 stackexchange 上看到的一个回复 by Andrew Hacking,随手分享下:

In my own experience with Bootstrap and simple_form / form_builder approach is that simple_form is not worth the trouble. There are just too many things that simple form has no answer for layout and control wise, some key black spots being classes on wrapper tags, selects with html attributes, or doing something simple like bootstrap button groups that mimic toggle/radio buttons. The i18n support in simple_form has also been a challenge, requiring a lot of duplication.

Also consider if server side rendering is the right approach for a modern application. I am transitioning from traditional rails/server-side rendering to a SPA (Single Page Application) model. To do this I'm using backbone.js and marionette with eco templates and coffeescript.

Architecturally the simple_form / rails form builder approach seems kind of flawed and within it has a lot of convoluted code for essentially building a html string fragment.

Well I say that is what view templates are for!

At the end of the day a view is composed from many different sub-view templates (eg partials), and I think it should go right down to control/field components. In contrast, the builder approach is always caught out with lack of support for different jquery components and is not really agile enough to keep pace.

I'd suggest using parameterised view templates/partials that codify the markup you want for each type of control/component or view construct in your app and simply compose them to get the layout you want. If you're doing this server side, you could wrap up all the render partial calls with some helpers for syntactical sweetness. If you're doing it client side with say eco templates, check the main page, you will see an example of defining and calling form building templates there.

Don't lock yourself into the capabilities of a form builder, use the boostrap documentation examples as the starting point for your templates and simply call them!

Agree.

从来都是用最原生的方式写 view,顶多换个语法……糖吃多了不好。

同意,很厌烦 simple_form 这种看似会带来生产力的东西,直接用 html 最干净,简洁!

再转一个 railscast 上的用户评论 hackeron about 2 years ago: Seems simple_form has quite a few bugs with Mongoid and doesn't work properly at all - the authors simply say "we don't use mongoid, we don't care" :( - Any alternatives that work well with Mongoid?

+1 很早就开始用 simple_form,当时看到这么简洁,太酷了。 在后面的使用过程中,发现定制起来不容易,有时为了加一些标签,写了一些奇怪的嵌层…… 现在都直接用原生的或bootstrap_form,后者的接口和原生 helper 是对应的,所以感觉挺不错。

先原生,再自己抽成 helper

需要 登录 后方可回复, 如果你还没有账号请 注册新账号