Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > ruby web programming, how to associate a relative link and a method?

Reply
Thread Tools

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

 
 
anne001
Guest
Posts: n/a
 
      06-10-2006
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?

 
Reply With Quote
 
 
 
 
anne001
Guest
Posts: n/a
 
      06-11-2006
I think I found a website which explains how it is done.
http://wiki.rubyonrails.com/rails/pa...uestsAreRouted

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!

 
Reply With Quote
 
 
 
 
anne001
Guest
Posts: n/a
 
      06-14-2006
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?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Question about DDP Format and associate workflow !! alex.buisson@googlemail.com DVD Video 0 02-19-2008 07:45 AM
RE: Link Link Link =?Utf-8?B?REw=?= Windows 64bit 0 05-17-2005 12:15 PM
Re: Link Link Link DANGER WILL ROBINSON!!! Kevin Spencer ASP .Net 0 05-17-2005 10:41 AM
Event associate is lost if link button is created outside of page_load Dailan ASP .Net 0 06-16-2004 07:24 PM



Advertisments