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
0
votes
0 answers

Update more than one column during AASM state transition

I am using ruby's aasm gem to implement a state machine and want to update a different column apart from the state itself during one of the transitions. For example: event :transact do # This will make two calls to the database. Ideally we should…
0
votes
0 answers

Is there a way to change database connection for aasm in ruby in a multi-database setup?

We are connecting to multiple databases. And we are using aasm gem to switch state from created to syncing. However, while switching states aasm throws an error ActiveRecord::ConnectionNotEstablished (connection is closed): Any guidance would be…
Purusottam
  • 611
  • 6
  • 19
0
votes
1 answer

ransack + AASM: ArgumentError wrong number of arguments (given 1, expected 0)

I faced the following error when running filtering using ransack: ArgumentError wrong number of arguments (given 1, expected 0) and stack trace is showing this: object.ransack(query_params) When dug deeper I have found that the error appears in…
mazikwyry
  • 197
  • 1
  • 10
0
votes
1 answer

Is this use of a Ruby eval method really dangerous, and if so what's the alternative? (Rails)

Okay so I'm using AASM in my Rails app to manage workflows around my User model. In the view layer, I want to make a little dropdown that displays all the available transitions for a given user and perform that transition when clicked, which adjusts…
stooshie45
  • 39
  • 7
0
votes
1 answer

ruby aasm gem: event name change, but permitted method still ask for old event name

I have been using aasm gem (https://github.com/aasm/aasm) to define an object. It comes with several public method for events. For example: With object a_machine, event boot_up would transit the object to a new state greeting. I would be able to do…
Dr Linh Chi Nguyen
  • 1,063
  • 1
  • 9
  • 17
0
votes
1 answer

AASM + Rspec - How to ignore/disable/skip the transition callbacks in a tests?

I have a class like this class Job include AASM aasm do state :created, initial: true state :processing, :notifying, :finished, :error event :process do before do # do some undesired stuffs for test end …
0
votes
1 answer

AASM event and Rails model with the same name?

How would I be able to use an event called ship in AASM if I also have a Rails model with that name? event :ship do transitions :from => :quoted, :to => :shipped end class Ship < ApplicationRecord end Whenever I call the Rails method .ship AASM…
Tintin81
  • 9,821
  • 20
  • 85
  • 178
0
votes
0 answers

Adding a default ordering to a has_many association prevents state transitions on model using AASM

So this is a very strange issue, and I have no idea what's going on. Based on an issue in our app, we wanted a has_many association to be returned with a default ordering applied to it every time you read the association from the database. I…
Siraris
  • 1,088
  • 3
  • 13
  • 21
0
votes
1 answer

Yield items in AASM after callback

Can you yield items inside an :after callback? I got LocalJumpException when I execute the code below require 'aasm' class TestClass include AASM aasm do state :created, initial: true state :running event :run do transitions…
Rod
  • 103
  • 3
0
votes
0 answers

Rails AASM does not rollback when validation returns false

I have a model Booking that changes the status using AASM models/booking.rb before_validation :item_availability, if: -> { pending? || approved? } enum status: [:pending, :approved, :rejected, :on_loan, :returned] aasm column: :status, enum: true,…
AllenC
  • 2,754
  • 1
  • 41
  • 74
0
votes
1 answer

AASM does not trigger ActiveRecord::Rollback

I have approve event enum in Booking model. I have a before_validation in approve in my model/booking.rb I added custom validation include AASM before_validation :item_availability, if: :approved? enum status: [:pending, :approved,…
AllenC
  • 2,754
  • 1
  • 41
  • 74
0
votes
0 answers

How to set the state with AASM?

I am attempting to build a learning application that has a quiz on it. The quiz is made up of several steps. I am using aasm to track the the user's state on the quiz. There are 3 states: 1.not started (Default state) 2.in progress…
Koko
  • 15
  • 3
0
votes
1 answer

ActiveAdmin + CanCan + AASM event switcher with AJAX

As an admin I have a specific role I want to see and switch event for object Depends on my role Inspired by activeadmin_addons and its Enum Integration I want to make similar functionality for AASM by letting diffent admin users change events…
alexey_the_cat
  • 1,812
  • 19
  • 33
0
votes
1 answer

Trouble testing for an error thrown from AASM gem

I'm having trouble testing for a thrown AASM error. Here is my controller method: # controllers/jobs_controller.rb def change_state respond_to do |format| if @job.close && @job.save format.html { redirect_to @job, notice: 'Job has been…
Stephen
  • 155
  • 2
  • 11
0
votes
1 answer

checking for a specific state not working when using multiple states per model (aasm)

Below are the states defined in my booking model. 1st state aasm :booking_state,namespace: :booking_state, skip_validation_on_save: true, :whiny_transitions => false do state :pending, initial: true state :some_other_states end 2nd state …
Abhilash
  • 2,864
  • 3
  • 33
  • 67
1 2 3
8 9