0
我需要状态机一点点的帮助,因为我与轨道4工作,我已经叫in_analysis等状态的初始状态称为批准,拒绝和各州批准,拒绝工作正常,我不通过各州对通问题,但我不能恢复到初始状态称为in_analysis,这里是我的代码:状态机导轨4不返回到初始状态
应用程序/模型/ profile.rb
state_machine :state, :initial => :in_analysis do
state :in_analysis, :approved, :rejected
state :approved do
validates :name, presence: true
end
event :approved do
transition in_analysis: :approved
end
event :reject do
transition in_analysis: :rejected
transition approved: :rejected
end
end
和我的控制器我有这个:
def update
@profile.state = :in_analysis
@profile = current_user.profile
respond_to do |format|
if @profile.update(profile_params)
format.html { redirect_to edit_profile_path(@profile), notice: t(:update, scope: [:messages, :controllers, :profiles, :successfully]) }
format.json { render :show, status: :ok, location: edit_profile_path(@profile) }
else
format.html { render :edit }
format.json { render json: @profile.errors, status: :unprocessable_entity }
end
end
end
所以我的目标是当配置文件更新状态回到最初的“in_analysis”,但我不知道为什么不起作用,因为另一个状态运行良好。
感谢您的时间!问候 !
哇感谢你的是,我只需要交换我的台词! –
如果我的回答解决了您的问题,请标记为接受的答案,以便其他人可能知道:) – vutran