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?
Can you duplicate the problem in a non rails example?
Would save me some time...
Pat.
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.
>
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
rules = Rools::RuleSet.new '/rails/purl/businessrules/salutations.csv'
generates the error:
rule_0
Anonymous modules have no name to be referenced by
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!