Archived

This forum has been archived. Please start a new discussion on GitHub.

ruby-rails example code?

Does anyone have a sample rails demonstration application to share?
I am intrigued by ruby on rails but don't have the knowledge to implement an IceRuby example. I have a great demo database server which is based upon the demo/Ice/session example. The corresponding IceRuby demo client slightly modified lets me see the power of Ruby.
What I can't get a handle on is how rails would create and maintain the connections through the proxy objects, and how effective or ineffective this would be.
This would great help in making the decision about the web client development environment.

Comments

  • dthompson wrote: »
    Does anyone have a sample rails demonstration application to share?
    Not a full-blown Rails application, just a tiny example how one could cobble together some demo:

    Assuming that you have the Ice demo tarball, you can start as follows:

    (1) Create a new Rails application: rails Ice
    (2) Copy "demo/book/printer/Printer.ice" to "Ice/public/Printer.ice"
    (3) Create a Rails controller: ./script/generate controller Ice ping
    (4) Edit "app/helpers/ice_helper.rb" to make it wrap the Ice::Application, resp. the Printer proxy
    require 'Ice'
    
    Ice::loadSlice(File.join([File.dirname(__FILE__),'..', '..', 'public'],'Printer.ice'))
    
    module IceHelper
      class Client < Ice::Application
        def run(args)
            printer = Demo::PrinterPrx::checkedCast(
              Ice::Application::communicator().stringToProxy(
                "SimplePrinter:default -p 10000"))
            if not printer
              puts $0 + ": invalid proxy"
              return false
          end
    
          printer.printString("Hello World!")
      
          return true
        end
      end
    end
    
    (5) Invoke the Proxy in "app/controllers/ice_controller.rb"
    class IceController < ApplicationController
    
      def ping
        IceHelper::Client.new().main(ARGV)
      end
    
    end
    
    (6) Start the web server: ./script/server
    (7) Start the "Printer" server, e.g., the C++ version: "demo/book/printer/server"
    (8) Open http://localhost:3000/ice/ping

    Take care,
    Andreas
  • Thanks Andreas. This will be great for me to get started. I think I can learn enough from this example to adapt to my specific sample ap.

    Don