dblack / wobblini.net wrote:

>
> I can see what kind of problem you're trying to solve, but in this
> case I can't seem to see beyond:
>
>    ar_object.do_something
>    cgi_object.do_something_next
>
> which means I'm not seeing how the program is designed.  Can you
> elaborate?  It might even help to see the global variable version, so
> that I can see where in the code the two objects are and why they have
> to be aware of each other.
>
>
> David
>

Here is the part of the code I am interested in:

require 'cgi'
require 'rubygems'
require_gem 'activerecord'

comment_cgi = CGI.new

@article = comment_cgi['article']
@user	= comment_cgi['user']
@comment = comment_cgi['comment']

class Comment < ActiveRecord::Base
	after_save :redirect

	def redirect
		$ok = 'yes'
	end
end

new_Comment = Comment.create(
  :article_id	=>	@article,
  :user_id	=>	@user,
  :comment	=>	@comment)

if $ok == 'yes'
   comment_cgi.out {"foo"}
else
   comment_cgi.out {"problem."}
end

So what I am doing here is "after_save :redirect" is setting the global
variable $ok to "yes" if the Comment object was successful in its
dealings with the database. Then the conditional statement turns
control back over to the CGI object allowing it to proceed (ultimately
with a page redirect).

I know I am reinventing the wheel here because Rails make this kind of
thing so easy but I am avoiding Rails at this point so I can really dig
into the Ruby language and understand it.

Thank you. TOD