rule_0, Anonymous modules have no name to be referenced by

74 views
Skip to first unread message

doug

unread,
Aug 14, 2007, 3:08:22 PM8/14/07
to Rools-dev
i created offer_test.rb to read offers.csv and tested ok

i take the code from the offer_test.rb file and put in
offer_controller.rb

i get error:
rule_0, Anonymous modules have no name to be referenced by

here is offers.csv:

rule-set,Define Offer
parameter,Person
Condition,Consequence
person.personicx == #{personicx},$offer = #{offer}
Personicx,Offer
1,College Student
2,General Consumer

here is offer_controller.rb:

class OfferController < ApplicationController

require 'rools'
require 'uri'

class Person

attr_accessor :name, :personicx

def initialize(name, personicx)

@name = name

@personicx = personicx

end

end

def index

a = "/store/show_by_tags/"

sally = Person.new("sally", 1)

peggy = Person.new("peggy", 2)

rules = Rools::RuleSet.new "/rails/purl/businessrules/
offers.csv"

rules.assert sally

a += $offer

a = URI.escape(a)

redirect_to a

end

end

can anybody suggest a fix for this error?

Pat Cappelaere

unread,
Aug 14, 2007, 3:26:38 PM8/14/07
to rool...@googlegroups.com
Doug,

Can you duplicate the problem in a non rails example?
Would save me some time...
Pat.

doug

unread,
Aug 15, 2007, 1:23:08 PM8/15/07
to Rools-dev
this is the working code i used as a basis for my rails app:

require 'test/unit'
require 'rools'
require 'rools/base'
require 'logger'

class Person
attr_accessor :name, :personicx

def initialize(name, personicx)
@name = name
@personicx = personicx
end
end

class OfferTest < Test::Unit::TestCase

def setup
#Rools::Base.logger = Logger.new(STDOUT)
end

def test_offers


sally = Person.new("sally", 1)
peggy = Person.new("peggy", 2)

#rules = Rools::RuleSet.new 'offers.csv'
rules = Rools::RuleSet.new '/rails/purl/businessrules/offers.csv'

rules.assert peggy

puts $offer


end
end

this code works in a command prompt (ruby offer_test.rb), and, i
thought all i would need to do to use it in a rails app was add:

require 'rools'

and

rules = Rools::RuleSet.new '/rails/purl/businessrules/offers.csv'

however, the line above is what generates the error:

rule_0


Anonymous modules have no name to be referenced by

in the rails app

i don't know how to get the code to fail in a non-rails app

On Aug 14, 2:26 pm, Pat Cappelaere <cappela...@gmail.com> wrote:
> Doug,
>
> Can you duplicate the problem in a non rails example?
> Would save me some time...
> Pat.
>

doug

unread,
Aug 15, 2007, 2:21:53 PM8/15/07
to Rools-dev
pat

thought you might want to see the full error:

Rools::RuleCheckError in OfferController#index

rule_0
Anonymous modules have no name to be referenced by

RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace

c:/ruby/lib/ruby/gems/1.8/gems/rools-0.3/lib/rools/rule_set.rb:56:in
`load_csv'
c:/ruby/lib/ruby/gems/1.8/gems/rools-0.3/lib/rools/rule_set.rb:152:in
`new'
c:/ruby/lib/ruby/gems/1.8/gems/rools-0.3/lib/rools/rule_set.rb:152:in
`rule'
(eval):1:in `load_csv'
#{RAILS_ROOT}/app/controllers/offer_controller.rb:64:in `new'
#{RAILS_ROOT}/app/controllers/offer_controller.rb:64:in `index'

doug

doug

unread,
Aug 17, 2007, 3:53:23 PM8/17/07
to Rools-dev
any .csv file i try to read in a controller class generates the same
error, for instance:

rules = Rools::RuleSet.new '/rails/purl/businessrules/salutations.csv'

generates the error:

rule_0
Anonymous modules have no name to be referenced by

doug

unread,
Aug 17, 2007, 4:41:13 PM8/17/07
to Rools-dev
thanks, pat, for the fix...

moved my anonymous Person class to app\models and everything is ok

should have had it there in the first place as i will eventually have
a persons table in my database

learned something new, today, about classes and ruby and rails

Rools does rule!

Reply all
Reply to author
Forward
0 new messages