Questions tagged [aasm]

A library for adding finite state machines to Ruby classes.

Started as the acts_as_state_machine plugin but has evolved into a more generic library that no longer targets only ActiveRecord models.

Supports

  • States
  • Machines
  • Events
  • Transitions
132 questions
1
vote
2 answers

AASM transition from but except one state

I have AASM with ActiveRecord model. Have many statuses and events with their transitions. I want to create event that will allow transition from any state except one. event :set_vacant_pass do transitions to: :vacant_pass, from: ?? end
alexey_the_cat
  • 1,812
  • 19
  • 33
1
vote
0 answers

Store aasm state value as capitalized strings

I was looking to implement this wonderful gem called aasm to my existing project. In my current project, the status column on which I am trying to add aasm, the values are saved as a capitalized string like 'Draft', 'Published' etc How do I define…
Abhishek Jain
  • 238
  • 2
  • 5
1
vote
1 answer

aasm undefined method `state'

I'm configuring my rails 5.1.4 model to support states via aasm, I'm having a problem with it, apparently it doesn't initialize the method state for the model. Which seems to be used when I call item.save so breaks my model. Other methods seem to…
Don Giulio
  • 2,946
  • 3
  • 43
  • 82
1
vote
1 answer

change AASM state through edit action

I'm using AASM to manage states in my User model. I want to change the status through the edit action. To do this I'm using the method User.aasm_states_for_select in my form to populate the select input for states. When I hit the button commit all…
1
vote
2 answers

Efficiently fetching records on multiple condition

Using aasm statemachine for model Booking. The state machine have below states state :payment_authorized state :payment_captured state :payment_failed state :some_more_states So to fetch bookings based on state I can call…
Abhilash
  • 2,864
  • 3
  • 33
  • 67
1
vote
2 answers

Pass a parameter to aasm event

I am using aasm statemachine. I have the below event. What this does is changes the state from order_created to payment_response_received. So after changing this I want to call a method verify_payment_response(data). I can make this state change by…
Abhilash
  • 2,864
  • 3
  • 33
  • 67
1
vote
0 answers

Is there an AASM method to get the next state if an event is fired without actually firing the event in rails

I'm trying to build a flow diagram for AASM. I have a state machine with lots of states and lots of event for each state. It's difficult visualise the machine from the AASM state machine definition. To do this I'd like three methods as follows, 1) A…
RamJet
  • 293
  • 1
  • 2
  • 13
1
vote
1 answer

After adding aasm gem, application gives me error: wrong number of arguments (given 1, expected 0)

My model: class Lead < ApplicationRecord include AASM aasm column: 'status' do state :new, initial: true state :valid event :submit do transitions from: :new, to: :valid end ... end ... end And the…
Ashan Priyadarshana
  • 3,119
  • 3
  • 29
  • 34
1
vote
2 answers

No route matches [PUT] "/articles" but I included the put route in routes

Hi I'm new to rails and MVC but I'm trying really hard to learn. Right now I'm using AASM to make a transition from in_draft to published. I'm being able to make the change in rails console but when trying to use a link_to I got the error in the…
jean182
  • 3,213
  • 2
  • 16
  • 27
1
vote
1 answer

Multiple state machines in one model for enum fields with aasm

I am using Rail 4.2.3 and aasm gem version 4.1 Is it possible to add two state machines in one model for enum fields? I have enum state: [:active, :suspended, :deleted] and enum activity: [:working, :stopped] and I wont 2 state machines like…
user1136228
  • 967
  • 9
  • 22
1
vote
1 answer

aasm ruby gem: super user without restrictions

Given the next model using the aasm gem: class Job include AASM aasm do state :sleeping, :initial => true state :running, :cleaning event :run do transitions :from => :sleeping, :to => :running end event :clean do …
ascherman
  • 1,762
  • 2
  • 20
  • 41
1
vote
1 answer

Is there a way using AASM with states and transitions configured by user?

I am using AASM with rails and I have been searching around for a solution for my problem, i need to make a state machine system configured by user. Imagine this scenario: the user visit the States CRUD page the user creates a new state X and a…
1
vote
2 answers

How to use model concerns in rails

I am trying to move different parts of a model into concerns. Two of each are the states defined by AASM, and attachments with Paperclip. So, I am moving the related codes into separate files. app/models/concerns/user_aasm.rb class User module…
Chris Yeung
  • 2,613
  • 6
  • 34
  • 57
1
vote
1 answer

AASM4.1.1 can't work on Rails4

I have a model that contain a field called "status".I have change it into String type in DB.And I also use enum in AASM. here is my code: class Card < ActiveRecord::Base include AASM enum status: { default: 0, published: 1, deleted:…
Madison Rong
  • 27
  • 1
  • 7
1
vote
1 answer

Reuse scope in query with has_many relationship to same STI table

Child1 and Child2 have an STI relationship with Entity, and Child2 has_many Child1. Child1 has a status column managed by AASM. class Entity < ActiveRecord::Base end class Child1 < Entity include AASM aasm_column 'status' do state :owned…
iftheshoefritz
  • 5,829
  • 2
  • 34
  • 41
1 2 3
8 9