Good shape mates for Sinatra?

I am starting to make forms and I am looking for form helpers in Sinatra.

  • Sinatra does not seem to have built-in form helpers.
  • The helpers in Padrino look like me, but I don’t feel like porting my application to another structure. In addition, it begins to look like a Rails application.
  • I did not find any helpers in the Sinatra form that are the de facto choice.

Ideally, I get only a set of decent form helpers that I can turn on as a gem and just start using, instead of manually wrapping all the basic erb / haml / ruby ​​levels.

What are your recommendations?

+4
source share
2 answers

I find sinatra-formhelpers useful and use it in some projects. Check out their Github page , the code is pretty simple and maybe just what you are looking for. Even if not, you can easily add your specialized helpers. You can just install it with

 gem install sinatra-formhelpers 

and use it, requiring a gem:

 require 'sinatra/form_helpers' 

or, if you are a subclass of Sinatra::Base , optionally including helpers:

 class MyApp < Sinatra::Base helpers Sinatra::FormHelpers # ... end 

After all, part of Sinatra's philosophy should be as light as possible. Therefore, if you want all the fancy stuff to be built in, Sinatra might just not be the right tool.

+3
source

I recommend using sinatra-formhelpers-ng because it fixes the error in sinatra-formhelpers .

I also found sinatra-formhelpers useful, but it did not seem to be supported, and I ran into an error: the state of SELECT tags is not saved through form submissions. In other words, if I create a form with several fields and two drop-down lists (SELECT tags), all fields are saved if I want to repeat the form in POST due to a failed check, except for SELECT tags. I fixed this and clicked on the original sinatra-formhelpers . The push was accepted, but the stone was not updated. I waited a couple of weeks and then unclenched it to sinatra-formhelpers-ng .

+4
source

All Articles