我的注册控制器中有以下代码(在创建方法中):
respond_to do |format|
if discount_code && invalid_discount_code
flash[:notice] = error_notification
format.html { render action: "new" }
elsif already_registered
flash.now[:error] = error_notification
format.html { redirect_to root_url }
elsif @user.save
events_history_hash = JSON.parse(@user.events_history)
@user.skip_confirmation!
sign_in @user
if events_history_hash[Current_event_id.to_s]["payment"] && events_history_hash[Current_event_id.to_s]["payment"] == 0
flash[:notice] = "Your complimentary registration for this event has been accepted."
format.html { redirect_to root_url }
elsif auto_approve
payment = extract_payment_from_events_history_json(@user.events_history)
format.html { redirect_to new_stripe_payment_path(:registration_payment => payment) }
else
EventMailer.send_email_to_admins_to_process_invite_request(current_user).deliver
flash[:notice] = INVITE_REQUEST_RECEIVED
format.html { redirect_to root_url }
end
else
format.html { render action: "new" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
该代码在我的开发环境(我的 MAC 本地)上运行得非常好,如果 auto_approve 为真,它会将我重定向到支付页面,但是当我将代码上传到测试服务器时,它总是会执行
EventMailer.send_email_to_admins_to_process_invite_request(current_user).deliver
即使 auto_approve 设置为 true。我通过在测试服务器上运行控制台验证了这一点。我还应该寻找什么?
可能是黑客:
这可能是一个黑客,但它解决了问题。在 test.rb 中,我将 config.serve_static_assets 的值从 false 更改为 true(默认情况下,在 test.rb 和 production.rb 中设置为 false,但在 development.rb 中设置为 true)
config.serve_static_assets = true