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

  • Home
  • SEARCH
  • 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 6990737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:23:47+00:00 2026-05-27T19:23:47+00:00

I am developing application in rails , where i have made use of state_machine

  • 0

I am developing application in rails , where i have made use of state_machine (https://github.com/pluginaweek/state_machine/).

Here i wanted to check condition in one state , based on condition
state changes from another state . (i.e consider state1 , state2 and
state3 are states if(a>b) {state1 => state2 }else {state1 =>state3})
,

i wanted to know how this will be accomplished in state machine .
kindly help me out in this

  • 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-05-27T19:23:48+00:00Added an answer on May 27, 2026 at 7:23 pm

    In state_machine, you define events that change the state of the underlying object. You can also set the state attribute to the state that you want.

    In your case you’d do:

    a.state = a > b ? "state2" : "state3"
    a.save!
    

    You can also check the state with:

    a.state1?
    

    What you should do is define an event that describes the transition from state1 to state2 or state3. For instance:

    state_machines :state, initial: :state1 do
      ... 
    
      event :go_to_state2 do
        transition state1: :state2
      end
    
      event :go_to_state3 do
        transition state1: :state3
      end
    
      ...
    end
    

    Then, you transition state like this:

    if a > b
      a.go_to_state2!
    else
      a.go_to_state3!
    end
    

    Using the events are a lot cleaner way of manipulating the state. This is all covered in the Readme on the plugin’s github page

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

Sidebar

Related Questions

I'm developing Rails application and I have to use authentication. I installed devise gem
I am developing a Rails application and would like to understand when to use
I have a Ruby on Rails application that I'm developing on my computer, which
I am developing a Ruby on Rails application with multilingual support. Now I have
I started developing my rails application using sqlite. I have reached a point where
I am developing a rails application in which I have two models User and
I have been developing a sample application after reading Rails 3 Tutorial book. In
I am developing a Rails 3 application and I have installed Capistrano on the
I am developing a Rails application that will access a lot of RSS feeds
I am currently developing a Rails application using a database that was designed before

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.