ruby without framework

Discussion in 'Ruby' started by Mohammed Rashad, Sep 7, 2010.

  1. [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?

    --
    Rashad
     
    Mohammed Rashad, Sep 7, 2010
    #1
    1. Advertising

  2. [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:
    --
    please don't print this e-mail unless you really need to.


    On Tue, Sep 7, 2010 at 9:31 PM, Mohammed Rashad
    <>wrote:

    > 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?
    >
    > --
    > Rashad
    >
     
    saurabh purnaye, Sep 7, 2010
    #2
    1. Advertising

  3. On Tue, Sep 7, 2010 at 9:31 PM, Mohammed Rashad
    <> wrote:
    > 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
     
    Martin DeMello, Sep 7, 2010
    #3
  4. Mohammed Rashad wrote:
    > 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.

    --
    Posted via http://www.ruby-forum.com/.
     
    Brian Candler, Sep 7, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anatoly Volodko
    Replies:
    1
    Views:
    2,166
    Mattias Sjögren
    Aug 14, 2003
  2. Charles A. Lackman
    Replies:
    1
    Views:
    1,439
    smith
    Dec 8, 2004
  3. Mark
    Replies:
    4
    Views:
    1,748
    Juan T. Llibre
    Nov 17, 2005
  4. moi
    Replies:
    3
    Views:
    4,089
    quaiser_ali
    Sep 26, 2008
  5. Replies:
    2
    Views:
    9,367
    Darryl L. Pierce
    Sep 11, 2005
Loading...

Share This Page