Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8579865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:42:10+00:00 2026-06-11T20:42:10+00:00

I’ve recently started messing with a gem called ‘ruleby’, a rule-engine for Ruby. The

  • 0

I’ve recently started messing with a gem called ‘ruleby’, a rule-engine for Ruby. The documentation for ruleby is a bit sparse, however, and I can’t seem to figure out how to properly reference associations for the rule-writing bit. I’m stumped both the ‘pattern’ part of the rule and also in the executing block part of the rule.

For example, let’s say I had a rule which would only be executed only when a user submitted a positive review. I could, for instance, write the following:

    rule :positive_review, [Review, :review, method.review_rating == "positive"] do |v|
        assert (store positive_review somehow)
    end

So it’s at this point that I get lost. I would like to write a rule which would reference back to the user and check the total number of positive reviews that the user of this positive review and possibly execute certain actions based on this number.

If anyone could point me in the right direction, I would be greatly appreciative. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:42:11+00:00Added an answer on June 11, 2026 at 8:42 pm

    I dont quite understand why you are asserting a fact inside of a rule, that should already be done. The github example code probably answered you by now but in case not:

    First you initialise the engine, I did it like this so I could call on it more than once.

    rule_engine = Ruleby::Core::Engine.new
    RULES_ENG = RulesEngineCaller.new(rule_engine)
    EngineRulebook.new(rule_engine).rules
    

    Then you assert your facts

    @events = Event.all
    @events.each do |event|
        @rule_engine.assert event
    end
    

    Then you run your engine

    @rule_engine.match
    

    if you want to add events you can just by calling assert per fact to the existing engine, it will just add to it until you either delete inside the engine or rebuild it.

    The rulebook is where you add your facts for me I did it programatically:

    class EngineRulebook < Rulebook
      def rules
        Rails.logger.debug "#{Time.now.utc} - Loading Rules into Rulebook"
        #msg = Notification.new()
        @rules = Rule.all
    
        @rules.each do |rule_name|
        case
         #hard coded rule - for auto cleaning
         when (rule_name.title == "SYSTEM ADMIN - auto-clean delete rule") && (rule_name.group.title == "Notification Admin")
          rule [Event, :m, m.terminate_flag == 1] do |v|
            if v[:m].rules.include?(rule_name) == false
              #output matched rule to console & logfile
              Rails.logger.info "#{Time.now.utc} - match rule #{rule_name.id} #{rule_name.title} - #{v[:m].ticket_id} - #{v[:m].description}"
    
              #add reference so rule doesn't fire again
              @event = Event.find_by_id(v[:m].id)
              @event.rules << rule_name
              v[:m].rules << rule_name
              modify v[:m]
              #Retract v[:m] would remove the fact from the rules engine, need to remove all related facts though
              #so dont use this as other rules may be requires as rules do not fire in order
            end
          end
       end
    

    I also did it as a case statement as I was loading rules programmatically. I also put a check in to say has this rule run before because each time you run the engine it will assess all facts, even ones that have already matched.

    Hopefully you have an answer, if not hopefully this helped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.