Ruby & Forms

Hi folks.

I’m trying to get my head around the implementation of Ruby forms. This
is not Rails. I’m messing around in Sinatra and wanted to know how to
receive submitted forms. I’ve looked at CGI and the params tag, but I’m
unclear as to which one should be used.

Any urls and insight appreciated as I can’t find much out there. I’m
confused between the two applications and I can’t seem to get params to
work properly.

Cheers

Am 13.12.2014 um 17:45 schrieb Bee.Lists:

I???m trying to get my head around the implementation of Ruby forms.

There’s no such thing… you mean HTML forms.

I???m messing around in Sinatra and wanted to know how to receive submitted
forms.

Use the params hash to access the data, see the example app below.

I???ve looked at CGI and the params tag, but I???m unclear as to which one
should be used.

Any urls and insight appreciated as I can???t find much out there.

There should be many examples online… for instance the Sinatra
documentation links to apps “In the Wild”.

Below a minimal example, save it into a file and run it:


require “sinatra”

get “/” do
erb :index
end

post “/submit” do
@first_name = params[:first_name]

erb :hello
end

END

@@layout

<%= yield %>

@@index

First Name:

@@hello

Hello, <%= @first_name %>!

Hi Marcus.

When I say Ruby, I mean receiving the form submission. “params” was
what I was looking for.

I will review your example. Thanks