ruby web programming, how to associate a relative link and a method?

Discussion in 'Ruby' started by anne001, Jun 10, 2006.

  1. anne001

    anne001 Guest

    I am using ruby and eruby to learn web programming

    The web exercise I am working on aggregates information from several
    data sources. The default computation is presented on the main rhtml
    page. I use eruby and open-uri to open the various html data sources
    and regular expressions to extract the info, I can then process the
    data and present it on the main rhtml page.

    But I don't know how to create a link to offer an alternative
    computation.
    I would like 127.0.0.1/erubyfiles/pgm.rhtml to call the default
    computation
    and to have an embeded relative link "/alt1" on that page which calls
    the alternative computation, with the code for that alternative
    computation in the same pgm.rhtml file.

    in the original example for AOL associating a relative link and code is
    done with
    ad_register_proc GET /alt1 pgm_alt1
    where pgm_alt1 is a procedure.

    how is this done in eruby? I will need to have methods, which means I
    need to have an explicit class. then how do I associate a relative link
    to one of the class method?
     
    anne001, Jun 10, 2006
    #1
    1. Advertising

  2. anne001

    anne001 Guest

    I think I found a website which explains how it is done.
    http://wiki.rubyonrails.com/rails/pages/UnderstandingHowRequestsAreRouted

    First I need to set up Apache so that it knows how to associate a URL
    and a directory
    and then I need to set an overide, and write a .htaccess file which
    will redirect me to a cgi file.
    >From there, I call either of 2 methods which generate the default or

    the alternative display
    depending on the display.

    Lets see if I have enough elements to get it to work!
     
    anne001, Jun 11, 2006
    #2
    1. Advertising

  3. anne001

    anne001 Guest

    For now I have a program with Nitro which maps a relative link to a
    method

    in the controller folder I have a main.rb file
    class Main
    def index
    @title = "Erb Example"
    @body = task1 + task2
    @urlname = "better still"
    @urladd = "alternate"
    emit
    end

    def alternate
    @title = "Advanced Example"
    @body = task2 + task1
    @urlname = "return"
    @urladd = "index"
    emit
    end

    private

    def task1
    return "1"
    end

    def task2
    return "2"
    end

    def emit
    template = ERB.new( html )
    template.result(binding)
    end

    def html
    "<html><head><title><%=@title %></title></head>
    <body>
    <%= @body %>
    <a href=<%= @urladd %>> <%= @urlname %></a>
    </body></html>"
    end
    end

    in the main directory a file run.rb
    #!/usr/bin/env ruby
    require 'nitro'
    require 'erb'
    require 'controller/main'

    Nitro.run(Main)
    which I run from unix with ruby -rubygems run.rb

    I have not shown I could do this with .htaccess, but I am assuming
    there must be
    ways like that to hard wire this type of behavior.

    So at one end, a hardwired solution, at the other end, complex
    frameworks, rails, nitro.
    Can this be done more lightly, in software without framework? with cgi,
    erb or eruby?
     
    anne001, Jun 14, 2006
    #3
    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. Angel
    Replies:
    2
    Views:
    602
    Kikoz
    Dec 26, 2003
  2. Dailan
    Replies:
    0
    Views:
    490
    Dailan
    Jun 16, 2004
  3. =?Utf-8?B?SmVUbUFu?=

    How do I associate one control with others>

    =?Utf-8?B?SmVUbUFu?=, Sep 24, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    759
    John Saunders
    Sep 24, 2004
  4. =?Utf-8?B?ZGF2aWQ=?=

    setup associate application with file type

    =?Utf-8?B?ZGF2aWQ=?=, Apr 25, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    391
    =?Utf-8?B?ZGF2aWQ=?=
    Apr 25, 2005
  5. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    941
    Kevin Spencer
    May 17, 2005
Loading...

Share This Page