我正在开发一个应用程序,其中有users
和projects
。每个用户都可以管理一个项目。无论如何,我希望用户在sign up
定义/选择他们的项目。用户和项目通过has many through
关联进行链接。
我已经使用form_for
将此代码添加到注册表单中。
<%= f.collection_select :project_ids, @projects, :id, :project_name, {}, { :multiple => false } %>
正在开发中:它运行完美!
在生产中:它坏了,我从Heroku得到"很抱歉,出了问题",用户没有创建。
日志没有给出失败的原因。
2013-11-27T20:40:11.087603+00:00 app[web.1]: Started POST "/users" for 66.44.22.241 at 2013-11-27 20:40:11 +0000
2013-11-27T20:40:13.443773+00:00 app[web.1]:
2013-11-27T20:40:13.443773+00:00 app[web.1]: Sent mail to tests@email.com (894ms)
2013-11-27T20:40:13.935915+00:00 app[web.1]: Started GET "/" for 66.44.22.241 at 2013-11-27 20:40:13 +0000
当我删除关联属性时,登录有效,日志看起来是一样的(至少对我来说)。
2013-11-27T20:45:21.122286+00:00 app[web.1]: Started POST "/users" for 66.44.22.241 at 2013-11-27 20:45:21 +0000
2013-11-27T20:45:22.402149+00:00 app[web.1]:
2013-11-27T20:45:22.402149+00:00 app[web.1]: Sent mail to tests@email.com (714ms)
2013-11-27T20:45:23.116820+00:00 app[web.1]: Started GET "/" for 66.44.22.241 at 2013-11-27 20:45:23 +0000
我的设备覆盖:
def create
@user = User.new(params[:user])
resource = @user
if resource.save
yield resource if block_given?
if resource.active_for_authentication?
flash[:notice] = "Signed up successsfully."
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
flash[:notice] = "Signed up successsfully."
expire_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
可能的问题是,在设备发送电子邮件后,设备之后的after_save正在回滚保存事务。如果用户建模,则将design语句移到底部,看看会出现什么有趣的东西。