这是我的 AASM
aasm column: :status do
state :pre_approval, initial: true
state :pending
state :opened
state :closed
event :approved do
transitions from: :pre_approval, to: :pending, guard: :approved?
end
event :received, after: Proc.new { set_received_date } do
transitions from: :pending, to: :opened
end
event :complete, after: Proc.new { set_completion_date } do
transitions from: :opened, to: :closed
end
end
这是我的新 API
module ServiceRequests
class API < Grape::API
version 'v1', using: :path
format :json
resource :companies do
params do
requires :company_id, type: Integer, desc: "A Company Id"
end
route_param :company_id do
resource :service_requests do
get do
Company.find(params[:company_id]).service_requests
end
end
end
end
end
end
这是我收到的错误:
AASM::InvalidTransition (Event 'approved' cannot transition from 'pending'):
我可以登录rails console
并运行Company.first.service_requests
,它运行良好,并且在我点击 时它在运行的应用程序中运行service_requests_path
,所以我不确定为什么这个 API 调用会导致问题