ruby without framework

  • Thread starter Mohammed Rashad
  • Start date
M

Mohammed Rashad

[Note: parts of this message were removed to make it a legal post.]

Can I use ruby code running in web browser without any frameworks used?
Also anyone please tell me how to make framework, Please give me some tips
or spark to start with.
I need to make a new framework because I need to re-use the ruby code
(actually shares the code) for desktop version and the new framework.

Is that possible?
 
S

saurabh purnaye

[Note: parts of this message were removed to make it a legal post.]

Hi Rashad,
For start you may use tiny frameworks, which you can use to study to create
framework.
Sinatra, Camping, Rack etc are the examples.
--
Thanks and Regards
Saurabh Purnaye
+91-9922071155
skype: sorab_pune
yahoo & gtalk: saurabh.purnaye
msn: (e-mail address removed)
 
M

Martin DeMello

Can I use ruby code running in web browser without any frameworks used?
Also anyone please tell me how to make framework, Please give me some tips
or spark to start with.
I need to make a new framework because I need to re-use the ruby code
(actually shares the code) for desktop version and the new framework.

Check out rack [http://rack.rubyforge.org/] - it's not a framework so
much as an interface that lets your app communicate with a webserver.

Also, what I've done in the past when I needed to share ruby code
between a desktop and web ui is to put most of it in libraries, and
have a small sinatra app that used those libraries.

martin
 
B

Brian Candler

Mohammed said:
Can I use ruby code running in web browser without any frameworks used?

The key thing to think about is, how does an incoming HTTP request end
up being processed by your ruby code? There are several options.

(1) Probably the most common option is to run a webserver written *in*
ruby (e.g. webrick), or in a combination of ruby and C (e.g. mongrel,
thin, unicorn). They will make a call to your code when the request
comes in.

Your app runs as a separate process, and listens on its own TCP socket.
So your URL might be something like http://x.x.x.x:4567/

If desired, you can proxy to this from another webserver in front.

(2) You can run Apache or Nginx with Phusion Passenger, a.k.a.
mod_rails. This integrates into the webserver, starting ruby processes
as necessary and passing HTTP requests to them using the Rack API.

(3) Your webserver can run your ruby script as a CGI, which means it
starts a new process running your script for each incoming request,
passing the request on STDIN and the headers in environment variables,
and getting the response on STDOUT. This is inefficient because it
involves starting a whole new ruby interpreter for each request. It
becomes extremely inefficient if your ruby code in turn loads lots of
other ruby libraries.

(4) There are some other options like FastCGI and SCGI, rarely used now.

Fortunately, all these options support mapping HTTP requests to the same
API: Rack. If you write your code using Rack, or any other framework
which sits on top of Rack (including Rails, Sinatra, Camping), then you
can run the same code under any of the above scenarios, just by changing
a config file.
Also anyone please tell me how to make framework, Please give me some
tips
or spark to start with.
I need to make a new framework because I need to re-use the ruby code
(actually shares the code) for desktop version and the new framework.

That depends on what you mean by "framework". Normally "framework" means
code someone has already written, that you plug your customisations
into. You don't write a new framework from scratch, you just pick one
and extend it.

For code which is shared between a desktop app and a web app: just put
it in a library (lib/foo.rb) which can be used by either.

To be honest, if you write a good web app, you won't need a desktop one,
and it will save you a lot of pain installing graphic libraries and
frameworks. Everyone has a browser; just point it at localhost. This is
where the web server written *in* ruby comes into its own.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top