DevHeads.net

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

Comments

Re: Ruby & Forms

By Panagiotis Atma... at 12/13/2014 - 14:42

Hello,

I’m building a small app using Sinatra. Here you can see the routes[1] and the views[2].

The “routes" are composed of two ‘paths’ the ‘get’ and the ‘post’ which ‘redirects’ depending on the situation.

The “views” are made using HAML which is a syntax-sugar for HTML like ERB, LESS, etc. I’m using CSS but you could use SASS instead if you like it...

NOTE: I’m using an MVC architecture (also called modular) Sinatra which you can see here: <a href="https://github.com/atmosx/pritory" title="https://github.com/atmosx/pritory">https://github.com/atmosx/pritory</a> based on riblits[3] skeleton.

If you need more details feel free to ask.

[1] <a href="https://github.com/atmosx/pritory/blob/master/routes/add_product.rb" title="https://github.com/atmosx/pritory/blob/master/routes/add_product.rb">https://github.com/atmosx/pritory/blob/master/routes/add_product.rb</a>
[2] <a href="https://github.com/atmosx/pritory/blob/master/views/add_product.haml" title="https://github.com/atmosx/pritory/blob/master/views/add_product.haml">https://github.com/atmosx/pritory/blob/master/views/add_product.haml</a>
[3] <a href="https://github.com/Phrogz/riblits" title="https://github.com/Phrogz/riblits">https://github.com/Phrogz/riblits</a>

Panagiotis (atmosx) Atmatzidis

email: <a href="mailto: ... at convalesco dot org"> ... at convalesco dot org</a>
URL: <a href="http://www.convalesco.org" title="http://www.convalesco.org">http://www.convalesco.org</a>
GnuPG ID: 0x1A7BFEC5
gpg --keyserver pgp.mit.edu --recv-keys 1A7BFEC5

"As you set out for Ithaca, hope the voyage is a long one, full of adventure, full of discovery [...]" - C. P. Cavafy

Re: Ruby & Forms

By Bee.Lists at 12/15/2014 - 11:57

Hi there. Thanks for the reply.

Yeah the whole Sinatra thing I have working. It’s the submission of forms which got me. I’m reading about ARGV and params, and I was having trouble getting around the latter. I will be taking a look at your Ruby though. It seems you’re just searching through params, so that’s essentially what I was looking for. I need more testing.

Cheers

Re: Ruby & Forms

By NBarnes at 12/13/2014 - 20:54

Does Ruby qua Ruby even have a concept of HTML forms? It seems like
that'd be something that would exist only in the context of
Ruby+RailsOrSinatra. I think that for someone to answer your question,
they'd have to understand Sinatra's form handling, rather than Ruby's.

On Sat, Dec 13, 2014 at 10:42 AM, Panagiotis Atmatzidis
< ... at convalesco dot org> wrote:

Re: Ruby & Forms

By =?utf-8?Q?l=C3=... at 12/13/2014 - 13:00

I do not understanding so much your question (my english is not good)
but, here I come:

For write form, I suggest you to use a template engine

slim is a good one ;)

for get forms values in sinatra, do a post methods and use the params
hash

post '/' do

puts params['fieldname']

end

The params hash value always contain the request info...

For work with sinatra, ALL you need is in the README

<a href="http://www.sinatrarb.com/intro.html" title="http://www.sinatrarb.com/intro.html">http://www.sinatrarb.com/intro.html</a>

Thread name: "Ruby & Forms"
Mail number: 1
In reply to: Bee.Lists