我想在format.html的respond_to操作上执行一些javascript。
window.top.location.href='#{ @recurring_charge.confirmation_url }'
我需要执行javascript来打开iframe窗口,否则我无法呈现页面,因为以下错误消息'X-Frame-Options'到'deny'。
我该怎么做?
def confirm_billing
current_shop.with_shopify!
@recurring_charge = RecurringCharge.new(recurring_charge_params)
if @recurring_charge.save
respond_to do |format|
format.html { render :js => "window.top.location.href='#{ @recurring_charge.confirmation_url }'" }
format.json { render json: { success: true, redirect_url: @recurring_charge.confirmation_url }, status: 201 }
end
else
respond_to do |format|
format.html { redirect_to root_url, notice: 'Something went wrong' }
format.json { render json: { success: false, errors: @recurring_charge.errors.full_messages }, status: 201 }
end
end
end
答案 0 :(得分:0)
我能够使用渲染来实现它:文本,无法相信它确实有效!
format.html { render :text => "<script>window.top.location.href='#{ @recurring_charge.confirmation_url }';</script>" }