标签: undefined

Rails,未定义的“原始”方法

我正在关注迈克尔·哈特尔的书,并一直在做一个我似乎无法弄清楚的可选练习。

我有一个帮手,叫

module MicropostsHelper

  def wrap(content)
    sanitize(raw(content.split.map{ |s| wrap_long_string(s) }.join(' ')))
  end
  private
    def wrap_long_string(text, max_width = 30)
      zero_width_space = "​"
      regex = /.{1,#{max_width}}/
      (text.length < max_width) ? text : 
                                  text.scan(regex).join(zero_width_space)
    end
end
Run Code Online (Sandbox Code Playgroud)

我正在尝试包装应该是用户输入中的字符串的内容。在我的控制器中,

def create
    flash[:notice] = "[][] is...", params[:micropost][:content]
    cleaned = wrap(params[:micropost][:content])
    @micropost = current_user.microposts.build(cleaned)
    ...
Run Code Online (Sandbox Code Playgroud)

但是我不断收到未定义的方法“原始”。有人可以解释为什么吗?

有没有显示方法示例的 api?

ruby-on-rails undefined

0
推荐指数
1
解决办法
1813
查看次数

未明确引用`strcpy_s'无法编译

我按照这本书,无法编译这个例子.有什么建议?

  1 #define __STDC_WANT_LIB_EXT1__ 1
  2 #include <string.h>
  3 #include <stdio.h>
  4 
  5 
  6 int main(void)
  7 {
  8         char source[] = "Here we go...";
  9         char destination[50];
 10 
 11         if(strcpy_s(destination, sizeof(destination), source))
 12                 printf("An error occurred copying the string.n");
 13 
 14 
 15         return 0;
 16 }
Run Code Online (Sandbox Code Playgroud)

错误:

/tmp/ccc5KZDZ.o: In function `main':
test.c:(.text+0x48): undefined reference to `strcpy_s'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

c reference undefined tr24731 strcpy

0
推荐指数
1
解决办法
5103
查看次数

for循环中的变量未定义?

运行Update()时,我收到一条错误,指出map [x]未定义为"map [x] [y] = rawmap [rawmapcount];" 而且我不确定为什么?

var currentuser;
var map = new Array(63);
for(x = 0;x < 36;x++) {
    map[x] = new Array(35);
}

function Update(login) {
    $.post("server.php",{update:1,login:login},function(data) {
        if(data == 0) {window.location.href = "WEBSITE";}
        else {
            var rawdata = data.split("[BRK]");
            currentuser = rawdata[0];
            var rawmap = rawdata[1].split("|");
            var rawmapcount = -1;
            var x;
            var y;
            for(x = 0;x < 64;x++) {
                for(y = 0;y < 36;y++) {
                    rawmapcount++;
                    map[x][y] = rawmap[rawmapcount];
                }
            }
        }
    });
}

Update(1); …
Run Code Online (Sandbox Code Playgroud)

javascript variables scope for-loop undefined

0
推荐指数
1
解决办法
643
查看次数

在Perl哈希中使用未初始化的值

我有一个脚本可以解析df到perl可以使用的东西.

 1 #!/usr/bin/perl
 2 use strict;
 3 use warnings;
 4
 5 my @headers = qw(name size used free capacity mount);
 6 my @df = `df -k`;
 7 shift @df;  # get rid of the header
 8
 9 my %devices;
10 for my $line (@df) {
11     my %info;
12     @info{@headers} = split /\s+/, $line;  # note the hash slice
13     $info{capacity} = _percentage_to_decimal($info{capacity});
14     $devices{ $info{mount} } = \%info;
15 }
16
17 # Change 12.3% to .123
18 sub …
Run Code Online (Sandbox Code Playgroud)

perl hash undefined

0
推荐指数
1
解决办法
6432
查看次数

JQuery不读取动态创建的元素属性

好吧,我认为这将是一个简单的问题,但我无法意识到Jquery如何失去/无法找到元素的属性:

使用Javascript:

for (var i=0; i<=10; i++)
{
    Cells[i]=document.createElement('div');
    Cells[i].id = "Cell"+String(i);
    Cells[i].className = "CellClass";
    if (i==0)//Let's look the fist one (neverminds which one).
    {
        alert(Cells[0].className);//This would alert: "CellClass" (without quotes).
        alert($("#Cell0").className);//This would alert: "undefined" (without quotes).
        //Another way:
        alert($(Cells[0]).className);//This would alert: "undefined" (without quotes).
    }
}
Run Code Online (Sandbox Code Playgroud)

对于这个问题,类.CellClass本身并不相关,永远不会明确哪些属性定义.

我不明白的是什么?

javascript jquery undefined

0
推荐指数
1
解决办法
608
查看次数

提交PHP时未定义的索引错误

我正在设计餐馆网站的表格,允许用户预订晚餐预订,每个字段都经过验证(除了复选框),如果用户在所有字段中输入了正确的信息,他们会被发送到感谢页面显示他们的预订细节.

我的代码中存在与我网站上的复选框有关的问题,如果用户点击提交而未填写必填字段,则会在屏幕顶部显示以下错误:

"Notice: Undefined index: vege in /home/users/2014/xxx/public_html/xxx/index.php on line 17

Notice: Undefined index: vegan in /home/users/2014/xxx/public_html/xxx/index.php on line 20

Notice: Undefined index: peanut in /home/users/2014/xxx/public_html/xxx/index.php on line 23

Notice: Undefined index: gluten in /home/users/2014/xxx/public_html/xxx/index.php on line 26"
Run Code Online (Sandbox Code Playgroud)

这是我的预订页面的代码:

<?php
session_start();

if ( isset($_POST['vege'])) 
    $_SESSION['vege'] = $_POST['vege'];

if ( isset($_POST['vegan'])) 
    $_SESSION['vegan'] = $_POST['vegan'];

if ( isset($_POST['peanut'])) 
    $_SESSION['peanut'] = $_POST['peanut'];   

if ( isset($_POST['gluten'])) 
    $_SESSION['gluten'] = $_POST['gluten'];

?>

...

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

...

<strong>Dietary Requirements:</strong>
<br><br>
Vegetarian <input type="checkbox" name="vege" …
Run Code Online (Sandbox Code Playgroud)

php variables indexing undefined

0
推荐指数
1
解决办法
497
查看次数

这段代码使用typeof ...!="undefined"和clearInterval做什么用的?

对于学校我需要用JavaScript编写一个游戏,但问题是我不明白这部分代码意味着什么:

if (typeof game_loop != "undefined") clearInterval(game_loop);
    game_loop = setInterval(paint, 60);
Run Code Online (Sandbox Code Playgroud)

javascript if-statement undefined

0
推荐指数
1
解决办法
216
查看次数

对于HelloWorld类型,方法JFrame未定义

我不知道为什么但是我的hello world java项目出错:

对于HelloWorld类型,方法JFrame是未定义的.

我刚刚开始,有人可以向我解释错误和解决方案吗?

package helloworld;

import javax.swing.JFrame;

public class HelloWorld {
    public static HelloWorld HelloWorld;
    public final int WIDTH = 800, HEIGHT = 800;

    public HelloWorld() {
        JFrame jframe = JFrame();
        jframe.setSize(WIDTH, HEIGHT);
        jframe.setVisible(true);

    }

    public static void main(String[] args) {
        HelloWorld = new HelloWorld();
    }
}
Run Code Online (Sandbox Code Playgroud)

java methods swing undefined

0
推荐指数
1
解决办法
89
查看次数

Firestore 在完全定义的 JSON 中找到未定义的值,键甚至不存在

我正在尝试将 JSON 对象上传到 Google Firestore。

将对象设置为 Firestore 文档时,我的代码会引发以下错误:

Error: Value for argument "data" is not a valid Firestore document. 
Cannot use "undefined" as a Firestore value 
(found in field audit.`20`.requests.`0`.lrEndTimeDeltaMs).
Run Code Online (Sandbox Code Playgroud)

现在我做的第一件事是在上传之前记录对象以检查未定义的值:

console.log(JSON.stringify(resultsToUpload));

return database
  .collection("foo1")
  .doc("bar1")
  .set(resultsToUpload);
Run Code Online (Sandbox Code Playgroud)

不仅在对象中定义了所有值,而且提到的字段audit.`20`.requests.`0`.lrEndTimeDeltaMs甚至不存在:

resultsToUpload = {  
  "audit":{   
    "20":{  
      "ronaldScore":3,
      "id":"network-requests",
      "requests":[  
        {  
          "url":"https://www.example.com/",
          "startTime":0,
          "endTime":62.16699999640696,
          "transferSize":15794,
          "resourceSize":78243,
          "statusCode":200,
          "mimeType":"text/html",
          "resourceType":"Document"
        }
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

数据来自 Google Lighthouse Audit。

计算字符串化 JSON 对象的 UTF-8 字符串长度会得到 30 MB 的大小。

1) 定义了所有值(有些为空,这应该不是问题)。

2) JSON 中甚至不存在上述字段。

我的问题是:这怎么会发生?一个字段怎么会出现?另外:我将如何解决这个问题?

json undefined node.js firebase google-cloud-firestore

0
推荐指数
1
解决办法
1376
查看次数

为什么我在使用 C 语言的 CodeVisionAVR 中得到未定义的符号“sprintf”?

我正在使用 C 在 CodeVision AVR 中进行编码,我想从 0 数到 100(计数器),然后将其显示在 Proteus 的 LCD 上。在 CodeVision 中选择“全部构建”时,出现此错误。我不知道为什么。

未定义符号 'sprintf'

编码:

#include <mega16.h>
#include <delay.h>
#include <alcd.h>
void main(void)
{
    int i;
    char buffer[10];
    lcd_init(16);
    while(1)
    {
        for(i=0;i<=100;i++)
        {
            lcd_clear();
            lcd_gotoxy(0,0);
            sprintf(buffer, "Time=%2d", i);
            lcd_putsf(buffer);
            delay_ms(100);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c printf lcd undefined codevisionavr

0
推荐指数
1
解决办法
475
查看次数