javascript - How to submit and receive forms in raw Ruby -


i'm new ruby , find extremely difficult learn in ruby not related rails.

i wanted know how have proceed submit html form ruby script , data in server side.

will work if send through xmlhttprequest (ajax)? if yes, how can send response javascript in json format? if not, why?

assuming want use post method, in php following

if(count($_post)>0){ //or, isset($_post['a_key'])    //do    echo json_encode($response); } 

in ruby tend rely on existing wheels. 1 that's popular sinatra, makes working post request simple:

require 'sinatra'  post '/'   # here end 

to convert json, use json class:

require 'json'  foo = {'a' => 1, 'b' => 2} puts foo.to_json # >> {"a":1,"b":2} 

mix , match necessary.

i read mechanize.

mechanize great when need navigate through website reading pages, filling in fields , clicking links , buttons. doesn't javascript , isn't useful when you're trying handle incoming requests. that's sinatra shines.

do recommend using rack instead?

rack isn't close mechanize there's no comparison. rack middle-layer inside httpd, , powerful. could use rack build out web server, it's not convenient sinatra. both sinatra , rails sit on top of rack, should tell rack does, , whether want try writing directly.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -