我在我的 Rails 4.2 应用程序中使用了响应者gem。我遇到了一个非常复杂的情况,在Organization
模型编辑视图中,我得到了一个OrganizationUser
带有一个输入的表单。将用户添加到组织会调用create
. OrganizationUsersController
我在那里使用响应者进行重定向操作,如下所示:
def create
@organization_user = @organization.organization_users.create(organization_user_params)
respond_with @organization_user do |format|
format.html { redirect_to edit_organization_path(@organization) }
end
end
还有我的翻译:
flash:
actions:
create:
notice: '%{resource_name} was successfully created.'
alert: '%{resource_name} could not be created.'
organization_users:
create:
notice: "Member has been added"
alert: "Validation error"
问题是,如果资源有效并且持久化到数据库,那么一切正常。我被重定向到编辑组织视图并带有适当的通知消息,但如果验证失败,我将被重定向而没有任何警报。
我当然可以设置闪光警报消息,除非@organization_user
被持久化,但这就是使用响应器自动设置闪光的全部意义所在。