问题描述
我开始制作表格,并在Sinatra中寻找表格助手.
I am starting to do forms and am looking for form helpers in Sinatra.
- Sinatra似乎没有内置的表单助手.
- 帕德里诺(Padrino)中的助手看起来像我想要的东西,但是我不愿意将我的应用程序移植到另一个框架.另外,它开始看起来像一个Rails应用程序.
- 我还没有找到任何事实"选择的Sinatra表单助手.
理想情况下,我只是想使用一组像样的表单帮助程序,将其作为宝石添加,然后开始使用它,而不是手动滚动所有基本级别的erb/haml/ruby表单构建.
Ideally, I'm after just a set of decent forms helpers that I can include as a gem and just start using, in place of hand-rolling all the base level erb/haml/ruby forms building.
您有什么建议?
推荐答案
我发现sinatra-formhelpers
有用,并在某些项目中使用了它.看看其Github页面,该代码非常简单,可能正是您所需要的为了.即使没有,您也可以轻松添加自己的专业助手.您可以简单地使用
I find sinatra-formhelpers
useful and used it in some projects. Have a look at their Github page, the code is pretty straightforward and might just be what you are looking for. Even if not, you could add your own specialized helpers easily. You can simply install it with
gem install sinatra-formhelpers
并通过需要宝石来使用它:
and use it by requiring the Gem:
require 'sinatra/form_helpers'
,或者,如果您是Sinatra::Base
的子类,则通过另外包括辅助对象:
or, if you subclass Sinatra::Base
, by additionally including the helpers:
class MyApp < Sinatra::Base
helpers Sinatra::FormHelpers
# ...
end
毕竟,辛那屈哲学的一部分是尽可能轻便.因此,如果您希望内置所有精美的功能,那么Sinatra可能不是正确的工具.
After all, part of Sinatra's philosophy is to be as light as possible. So if you want all the fancy things built in, Sinatra might just not be the right tool.
这篇关于Sinatra的好形式帮手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!