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

A

anne001

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?
 
A

anne001

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!
 
A

anne001

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?
 

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,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top