Bee.Lists
(Bee.Lists)
13 December 2014 16:45
1
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
stomar
(stomar)
14 December 2014 21:13
2
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:
···
Am 13.12.2014 um 17:45 schrieb Bee.Lists:
----------
require "sinatra"
get "/" do
erb :index
end
post "/submit" do
@first_name = params[:first_name]
erb :hello
end
__END__
@@layout
<!DOCTYPE html>
<html>
<body>
<%= yield %>
</body>
</html>
@@index
<form action="/submit" method="post">
<label for="zahl">First Name:</label>
<input type="text" name="first_name" value="">
<input type="submit">
</form>
@@hello
<p>Hello, <%= @first_name %>!</p>
----------
Best regards,
Marcus
--
GitHub: stomar (Marcus Stollsteimer) · GitHub
PGP: 0x6B3A101A
Bee.Lists
(Bee.Lists)
15 December 2014 15:59
3
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
···
On Dec 14, 2014, at 4:13 PM, sto.mar@web.de wrote:
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
<!DOCTYPE html>
<html>
<body>
<%= yield %>
</body>
</html>
@@index
<form action="/submit" method="post">
<label for="zahl">First Name:</label>
<input type="text" name="first_name" value="">
<input type="submit">
</form>
@@hello
<p>Hello, <%= @first_name %>!</p>
----------
Best regards,
Marcus