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?
Asked
Active
Viewed 1.9k times
1 Answers
44
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 Learn Ruby the Hard Way

Reuben Mallaby
- 5,740
- 4
- 47
- 45

jrom
- 1,910
- 1
- 16
- 12
-
3Just a heads up, that link isn't live anymore. – AlbertEngelB Oct 14 '14 at 15:19