我将以下代码片段从我的文本编辑器复制到我的rails控制台:
request = Typhoeus::Request.new(
"https://track.customer.io/api/v1/customers/4",
ssl_verifypeer: false,
method: :put,
headers: {
"Content-Type" => "application/json",
"User-Agent" => "#{Rails.configuration.customerio[:site_id]}:#{Rails.configuration.customerio[:api_key]}"},
body: '{
"email":"first@last.com",
"name":"Name is here",
"id":"4",
"created_at":"#{Time.now}"}')
Run Code Online (Sandbox Code Playgroud)
当我将它全部复制为一行时:
request = Typhoeus::Request.new("https://track.customer.io/api/v1/customers/4", ssl_verifypeer: false,method: :put,headers: {"Content-Type" => "application/json","User-Agent" => "#{Rails.configuration.customerio[:site_id]}:#{Rails.configuration.customerio[:api_key]}"},body: '{"email":"first@last.com", "name":"Name is here","id":"4","created_at":"#{Time.now}"}')
Run Code Online (Sandbox Code Playgroud)
然后控制台返回标准响应:
=> #<Typhoeus::Request:0x00000101c517a8 @base_url="https://track.customer.io/api/v1/customers/4", @original_options=...
Run Code Online (Sandbox Code Playgroud)
但是,如果我逐行复制它(就像我在第一个代码片段中所做的那样),我会收到一个奇怪的错误.控制台询问我是否要显示所有可能性,就像我正在搜索目录或在粘贴中途进行搜索查询一样.看看这个:
1.9.3p393 :091 > request = Typhoeus::Request.new(
1.9.3p393 :092 > "https://track.customer.io/api/v1/customers/4",
1.9.3p393 :093 > ssl_verifypeer: false,
1.9.3p393 :094 > method: :put,
1.9.3p393 :095 > headers: {
1.9.3p393 :096 >
Display all 573 possibilities? (y or n)
1.9.3p393 :096 > "Content-Type" => "application/json",
1.9.3p393 :097 >
Display all 573 possibilities? (y or n)
1.9.3p393 :097 > "User-Agent" => "#{Rails.configuration.customerio[:site_id]}:#{Rails.configuration.customerio[:api_key]}"},
1.9.3p393 :098 > body: '{
1.9.3p393 :099'> "email":"first@last.com",
1.9.3p393 :100'> "name":"Name is here",
1.9.3p393 :101'> "id":"4",
1.9.3p393 :102'> "created_at":"#{Time.now}"}')
Run Code Online (Sandbox Code Playgroud)
如果我同时选择n两次,则会正常创建请求.但是,如果我选择的话y,它会列出573项,其中大部分是我放入这个馅饼的:http://pastie.org/private/ksgzqhd50mvdi0t6cqe8g
你知道这些结果是什么吗,更重要的是,为什么在这个奇怪的时间被提示?
听起来像你要复制代码的源有两个制表符,其中"Content-Type"...和"User-Agent"...缩进.两个制表符将调用控制台中的自动完成列表(您看到的提示是当可能的完成次数超过某个阈值时).
请注意,如果您从自己的StackOverflow帖子中复制并粘贴它,则不应该看到自动完成提示,因为它使用空格来缩进而不是制表符.
编辑:
要确认我的怀疑,请在编辑器中打开"显示空白",以查看这两行的开头是否有制表符.
个人意见:如果您还没有这样做,我建议您配置编辑器为Tab键按下插入空格.标签是魔鬼的空白:).
| 归档时间: |
|
| 查看次数: |
1324 次 |
| 最近记录: |