我正在阅读Rails入门指南并与第6.7节混淆.生成脚手架后,我在控制器中找到以下自动生成的块:
def index
@posts = Post.all
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @posts }
end
end
Run Code Online (Sandbox Code Playgroud)
我想了解respond_to块实际上是如何工作的.什么类型的变量是格式?是格式对象的.html和.json方法吗?该文件对ActionController::MimeResponds::ClassMethods::respond_to不回答这个问题.
问题:我得到这个异常"的基础连接已关闭:意外错误发生在一个发送"我的日志,它是在随机时间打破了我们的OEM集成与我们的电子邮件营销系统从不同[1小时 - 4小时]
我的网站托管在带有IIS 7.5.7600的Windows Server 2008 R2上.该网站拥有大量的OEM组件和全面的仪表板.除了我们在仪表板中用作iframe解决方案的电子邮件营销组件之外,网站的所有其他元素都可以正常工作.它的工作方式是,我发送一个httpWebRequestobject与所有凭据,我得到一个网址,我把它放在一个iframe,它的工作原理.但它仅适用于一段时间[1 HOUR - 4小时],然后我得到下面的异常"的基础连接已关闭:意外错误发生在一个发送"即使系统尝试从HttpWebRequest的它获取URL失败,同样的例外.使其再次工作的唯一方法是回收应用程序池或在web.config中编辑任何内容.我真的很精疲力尽所有我能想到的选择.
明确添加, keep-alive = false
keep-alive = true
增加时间: <httpRuntime maxRequestLength="2097151" executionTimeout="9999999" enable="true" requestValidationMode="2.0" />
我已将此页面上传到非SSL网站,以检查我们的生产服务器上的SSL证书是否正在建立连接以放弃一些方法.
非常感谢任何解决方向.
代码:
Public Function CreateHttpRequestJson(ByVal url) As String
Try
Dim result As String = String.Empty
Dim httpWebRequest = DirectCast(WebRequest.Create("https://api.xxxxxxxxxxx.com/api/v3/externalsession.json"), HttpWebRequest)
httpWebRequest.ContentType = "text/json"
httpWebRequest.Method = "PUT"
httpWebRequest.ContentType = "application/x-www-form-urlencoded"
httpWebRequest.KeepAlive = False
'ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
'TODO change the integratorID to the serviceproviders account Id, useremail
Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream())
Dim json As …Run Code Online (Sandbox Code Playgroud) 点采购Powershell脚本时遇到一些范围问题。假设我有一个脚本“ A.ps1”:
$VERSION = "1.0"
# Dot source B.ps1
. .\B.ps1
function Write-Version { Write-Host "A.ps1 version $VERSION" }
Write-Version
Run Code Online (Sandbox Code Playgroud)
和脚本B.ps1
$VERSION = "2.0"
function Write-Version { Write-Host "B.ps1 version $VERSION" }
Write-Version
Run Code Online (Sandbox Code Playgroud)
运行A.ps1的输出将是:
B.ps1 version 2.0
A.ps1 version 2.0
Run Code Online (Sandbox Code Playgroud)
为什么发生这种情况非常明显。$VERSION来自B.ps1 的变量被放入A.ps1的范围,并覆盖该变量。的确确实发生了这种情况Write-Version,但是这里A.ps1覆盖了B的版本,但是由于Write-Version在此之前在B.ps1中被调用,我们仍然可以看到B的Write-Version函数的输出。
当然,问题是如何防止这种情况发生?我尝试了各种示波器选项,但是在点源采购时似乎不起作用。而且由于B.ps1中有我在A的作用域中确实需要的功能,因此仅调用B.ps1可能不是一种选择。
有人有什么想法吗?
我无法理解ScriptBlocks中的范围.我指望某种类似闭包的系统,但我似乎无法让它工作.
我有一个ScriptBlock拿a param并返回另一个ScriptBlock:
$sb1 = {
Param($Message1);
Write-Host $Message1;
{
Param($Message2);
Write-Host ($Message1 + " " + $Message2);
}
}
Run Code Online (Sandbox Code Playgroud)
为了得到内ScriptBlock我可以调用$sb1用$sb2 = & $sb1 -Message1 "Message1".这回应Message1所以我们知道它param是受约束的.
现在,我可以调用$sb2用& $sb2 -Message2 "Message2".我原以为Message1 Message2,但它只是写作而已Message2.
有没有办法访问$Message1变量?我不能使用本地或脚本变量,因为内部scriptblock的多个实例具有不同的$Message1s.
这是实际shell的实际输出:
PS C:\> $h1 = { Param($Message1); Write-Host $Message1; { Param($Message2); Write-Host ($Message1 + " " + $Message2); } …Run Code Online (Sandbox Code Playgroud) 抱歉标题令人困惑。
我正在尝试使用类似于https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html#keyof-and-lookup-typessetProperty中的示例的查找类型
调用函数时会正确检查查找类型,但不能在函数内部使用。我尝试使用类型保护来解决这个问题,但这似乎不起作用。
例子:
interface Entity {
name: string;
age: number;
}
function handleProperty<K extends keyof Entity>(e: Entity, k: K, v: Entity[K]): void {
if (k === 'age') {
//console.log(v + 2); // Error, v is not asserted as number
console.log((v as number) + 2); // Good
}
console.log(v);
}
let x: Entity = {name: 'foo', age: 10 }
//handleProperty(x, 'name', 10); // Error
handleProperty(x, 'name', 'bar'); // Good
// handleProperty(x, 'age', 'bar'); // Error
handleProperty(x, 'age', …Run Code Online (Sandbox Code Playgroud) 假设我有一个函数(可能来自第三方库,假设我无法更改其定义),以及一个具有与函数参数匹配或重叠的属性的对象:
function fn(foo, bar, baz) { /* do stuff */ }
var obj = { foo: "yes", bar: 7, baz: false }
Run Code Online (Sandbox Code Playgroud)
有没有办法使用某种解构或扩展赋值或其他一些 ES6 功能来将对象属性应用为函数参数,或者我是否坚持单独指定每个参数?
fn(...obj); // Doesn't work
fn(obj.foo, obj.bar, obj.baz); // Convoluted but works
fn.apply(null, obj.values()); // Might work if you're lucky
Run Code Online (Sandbox Code Playgroud) powershell ×2
scope ×2
closures ×1
connection ×1
ecmascript-6 ×1
javascript ×1
scriptblock ×1
ssl ×1
typescript ×1