tags:

views:

424

answers:

1

Is there some utilities available so that I could easily encapsulate form fields passed in requests in an object or do I have to create it myself by parsing fields from params in every request?

+3  A: 

Yes, since Sinatra 0.9 you can use Rails-like nested parameters:

You just declare your form as:

<form>
  <input ... name="post[title]" />
  <input ... name="post[body]" />
  <input ... name="post[author]" />
</form>

And then you just have to do:

@post = params[:post]

to fetch all the parameters in an object.

More information in The Sinatra Book # Form parameters.

jrom