Ruby on rails 我怎样才能得到一个双重渲染器?
我一直得到DoubleRenderError,虽然我知道Ruby有DoubleRenderError规则,但我的理解是,这并不意味着一个操作中不能有多个“render”语句。只是在代码的执行流中,“render”不应该被满足多次,但这在我的代码中并没有发生。有人能帮忙吗?代码如下:Ruby on rails 我怎样才能得到一个双重渲染器?,ruby-on-rails,Ruby On Rails,我一直得到DoubleRenderError,虽然我知道Ruby有DoubleRenderError规则,但我的理解是,这并不意味着一个操作中不能有多个“render”语句。只是在代码的执行流中,“render”不应该被满足多次,但这在我的代码中并没有发生。有人能帮忙吗?代码如下: class RegistrationsController < Milia::RegistrationsController skip_before_action :authenticate_tenant
class RegistrationsController < Milia::RegistrationsController
skip_before_action :authenticate_tenant!, :only => [:new, :create, :cancel]
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# TODO: options if non-standard path for new signups view
# ------------------------------------------------------------------------------
# create -- intercept the POST create action upon new sign-up
# new tenant account is vetted, then created, then proceed with devise create user
# CALLBACK: Tenant.create_new_tenant -- prior to completing user account
# CALLBACK: Tenant.tenant_signup -- after completing user account
# ------------------------------------------------------------------------------
def create
# have a working copy of the params in case Tenant callbacks
# make any changes
tenant_params = sign_up_params_tenant
user_params = sign_up_params_user
coupon_params = sign_up_params_coupon
sign_out_session!
# next two lines prep signup view parameters
prep_signup_view( tenant_params, user_params, coupon_params )
# validate recaptcha first unless not enabled
if !::Milia.use_recaptcha || verify_recaptcha
Tenant.transaction do
@tenant = Tenant.create_new_tenant( tenant_params, user_params, coupon_params)
if @tenant.errors.empty? # tenant created
if @tenant.plan == 'premium'
@payment = Payment.new({ email: user_params["email"],
token: params[:payment]["token"],
tenant: @tenant })
flash[:error] = "Please check registration errors" unless @payment.valid?
begin
@payment.process_payment
@payment.save
rescue Exception => e
flash[:error] = e.message
@tenant.destroy
log_action("Payment failed")
render :new and return
end
end
else
resource.valid?
log_action( "tenant create failed", @tenant )
render :new
end # if .. then .. else no tenant errors
if flash[:error].blank? || flash[:error].empty? #payment successful
initiate_tenant( @tenant ) # first time stuff for new tenant
devise_create( user_params ) # devise resource(user) creation; sets resource
if resource.errors.empty? # SUCCESS!
log_action( "signup user/tenant success", resource )
# do any needed tenant initial setup
Tenant.tenant_signup(resource, @tenant, coupon_params)
else # user creation failed; force tenant rollback
log_action( "signup user create failed", resource )
raise ActiveRecord::Rollback # force the tenant transaction to be rolled back
end # if..then..else for valid user creation
else
resource.valid?
log_action("Payment processing failed", @tenant )
render :new and return
end # if.. then .. else no tenant errors
end # wrap tenant/user creation in a transaction
else
flash[:error] = "Recaptcha codes didn't match; please try again"
# all validation errors are passed when the sign_up form is re-rendered
resource.valid?
@tenant.valid?
log_action( "recaptcha failed", resource )
render :new
end
end # def create
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
protected
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) + ::Milia.whitelist_user_params
end
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
def sign_up_params_tenant()
params.require(:tenant).permit( ::Milia.whitelist_tenant_params )
end
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
def sign_up_params_user()
params.require(:user).permit( ::Milia.whitelist_user_params )
end
# ------------------------------------------------------------------------------
# sign_up_params_coupon -- permit coupon parameter if used; else params
# ------------------------------------------------------------------------------
def sign_up_params_coupon()
( ::Milia.use_coupon ?
params.require(:coupon).permit( ::Milia.whitelist_coupon_params ) :
params
)
end
# ------------------------------------------------------------------------------
# sign_out_session! -- force the devise session signout
# ------------------------------------------------------------------------------
def sign_out_session!()
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name) if user_signed_in?
end
# ------------------------------------------------------------------------------
# devise_create -- duplicate of Devise::RegistrationsController
# same as in devise gem EXCEPT need to prep signup form variables
# ------------------------------------------------------------------------------
def devise_create( user_params )
build_resource(user_params)
# if we're using milia's invite_member helpers
if ::Milia.use_invite_member
# then flag for our confirmable that we won't need to set up a password
resource.skip_confirm_change_password = true
end
if resource.save
yield resource if block_given?
log_action( "devise: signup user success", resource )
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_flashing_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
expire_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
log_action( "devise: signup user failure", resource )
prep_signup_view( @tenant, resource, params[:coupon] )
respond_with resource
end
end
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
def after_sign_up_path_for(resource)
headers['refresh'] = "0;url=#{root_path}"
root_path
end
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
def after_inactive_sign_up_path_for(resource)
headers['refresh'] = "0;url=#{root_path}"
root_path
end
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
def log_action( action, resource=nil )
err_msg = ( resource.nil? ? '' : resource.errors.full_messages.uniq.join(", ") )
logger.debug(
"MILIA >>>>> [register user/org] #{action} - #{err_msg}"
) unless logger.nil?
end
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
end # class Registrations
类注册控制器[:新建,:创建,:取消]
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
#TODO:新注册视图的非标准路径的选项
# ------------------------------------------------------------------------------
#创建--在新注册时拦截创建后操作
#审查新租户帐户,然后创建,然后继续设计创建用户
#回调:Tenant.create_new_Tenant--在完成用户帐户之前
#回调:Tenant.Tenant\u注册--完成用户帐户后
# ------------------------------------------------------------------------------
def创建
#备有参数的工作副本,以防租户回调
#有什么变化吗
租户参数=注册租户参数
用户参数=注册用户参数
优惠券参数=注册优惠券参数
注销会话!
#接下来的两行准备注册视图参数
准备注册视图(租户参数、用户参数、优惠券参数)
#除非未启用,否则首先验证recaptcha
如果!::Milia.使用| | |验证|
承租人。交易做什么
@租户=租户。创建新租户(租户参数、用户参数、优惠券参数)
如果@tenant.errors.empty?#租户创建
如果@tenant.plan=='premium'
@payment=payment.new({email:user_params[“email”],
令牌:参数[:付款][“令牌”],
租户:@tenant})
flash[:error]=“请检查注册错误”,除非@payment.valid?
开始
@付款。处理付款
@付款,储蓄
救援异常=>e
闪光[:错误]=e.message
@承租人,销毁
记录操作(“付款失败”)
渲染:新建并返回
结束
结束
其他的
资源。有效吗?
日志_操作(“租户创建失败”,@tenant)
渲染:新
结束#如果。。然后。。否则没有租户错误
如果闪烁[:错误]。空白?| |flash[:错误]。是否为空#付款成功
启动_租户(@tenant)#新租户的第一次资料
设计创建(用户参数)#设计资源(用户)创建;集合资源
如果resource.errors.empty?#成功!
日志操作(“注册用户/租户成功”,资源)
#进行任何需要的租户初始设置
租户.租户注册(资源,@Tenant,优惠券参数)
否则#用户创建失败;强制租户回滚
日志操作(“注册用户创建失败”,资源)
raise ActiveRecord::Rollback#强制回滚租户事务
结束#if..then..else用于有效用户创建
其他的
资源。有效吗?
日志_操作(“付款处理失败”,@tenant)
渲染:新建并返回
结束#如果。。然后。。否则没有租户错误
结束#在事务中包装租户/用户创建
其他的
flash[:error]=“Recaptcha代码不匹配;请重试”
#重新呈现注册表单时,将传递所有验证错误
资源。有效吗?
@租客,有效吗?
记录操作(“recaptcha失败”,资源)
渲染:新
结束
结束#定义创建
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
受保护的
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
def配置\u允许的\u参数
为(:注册)+:Milia.whitelist\u用户参数设计参数
结束
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
def注册参数租户()
参数require(:tenant).permit(::Milia.whitelist_tenant_参数)
结束
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
def注册参数用户()
参数require(:user).permit(::Milia.whitelist\u user\u参数)
结束
# ------------------------------------------------------------------------------
#签名参数优惠券——允许优惠券参数(如果使用);其他参数
# ------------------------------------------------------------------------------
def注册参数优惠券()
(::Milia.使用优惠券吗?
参数要求(:优惠券)。允许(::Milia.whitelist_优惠券参数):
params
)
结束
# ------------------------------------------------------------------------------
#注销会话!——强制设计会话注销
# ------------------------------------------------------------------------------
def注销会话!()
设计、签出所有示波器?注销:如果用户登录,是否注销(资源名称)?
结束
# ------------------------------------------------------------------------------
#designe\u create--designe::RegistrationsController的副本
#与Desive gem中相同,只是需要准备注册表单变量
# ------------------------------------------------------------------------------
def设计
def custom_render(params)
byebug # Put breakpoint here
render params
end