我使用AASM来管理我的用户模型中的状态。
我想通过编辑操作更改状态。
为此,我在表单中使用User.aasm_states_for_select方法来填充州的select输入。当我点击commit按钮时,所有的更改都会被保存,包括状态名称。但该状态的AASM事件未被调用,这是因为只有字段状态已更改且事件方法未被调用。
有没有人能解决我的问题?
发布于 2017-11-08 18:37:20
不幸的是,唯一的解决方案是从状态名中找到事件并直接应用它。就像这样
STATE_MAPPING = {
'state_name' => :event_name
}
#...
def update
user.public_send(state_event) if state_event
user.update permitted_attributes
#...
end
# ...
def state_event
state = params.require(:user).permit(:state)[:state]
STATE_MAPPING[state]
end
def permitted_attributes
@params.require(:user).permit #attributes without state
end太匆忙了,但据我所知,没有其他可用的解决方案
https://stackoverflow.com/questions/47176765
复制相似问题