Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do html forms with sinatra?

Tags:

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?

like image 928
JtR Avatar asked Oct 08 '09 06:10

JtR


People also ask

How do I create a HTML form from a website?

Step 1: Firstly, we have to type the Html code in any text editor or open the existing Html file in the text editor in which we want to create the registration form. Step 2: Now, we have to place the cursor at that point where we want to create a form between the starting and closing of <body> tag in the Html document.

What is webforms in HTML?

Web Forms are pages that your users request using their browser. These pages can be written using a combination of HTML, client-script, server controls, and server code.


1 Answers

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

like image 70
jrom Avatar answered Sep 24 '22 01:09

jrom