# 导入脚本 ipboard3.rb 的问题

**URL:** https://meta.discourse.org/t/problem-with-import-script-ipboard3-rb/151783
**Category:** Support
**Created:** [2020年五月18日 04:08 UTC](https://meta.discourse.org/t/problem-with-import-script-ipboard3-rb/151783 "2020-05-18T04:08:04Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![dr3adx](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@dr3adx](https://meta.discourse.org/u/dr3adx)
#### Post date: [2020年五月18日 04:08 UTC](https://meta.discourse.org/t/problem-with-import-script-ipboard3-rb/151783/1 "2020-05-18T04:08:04Z")

</div>

我试图从我的 ipb 论坛导入数据，运行脚本 ipboard3 时出现以下错误：

```plaintext
script/import_scripts/ipboard3.rb:375:in `clean_up': undefined method `encode!' for nil:NilClass (NoMethodError)
root@forum:/var/www/discourse# `clean_up': undefined method `encode!'

```

为什么会提示“未定义方法 ‘encode!’”？😕

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2020年五月18日 17:23 UTC](https://meta.discourse.org/t/problem-with-import-script-ipboard3-rb/151783/2 "2020-05-18T17:23:27Z")

</div>

> [@dr3adx](#):
>
> 为什么会出现“未定义方法 ‘encode’”的错误？

这是因为调用时 `raw` 的值为 `nil`。

因此，你需要找出是哪个函数调用了它，以及为什么它没有获取到帖子的原始数据。

我猜问题出在这一行：

```
           bio_raw: clean_up(u["pp_about_me"]),

```

如果是这样，那么可能需要修改 `clean_up` 函数，使其在接收到空数据时返回 `nil`。

---

<div class="post-metadata">

### Author: ![dr3adx](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@dr3adx](https://meta.discourse.org/u/dr3adx)
#### Post date: [2020年五月19日 00:54 UTC](https://meta.discourse.org/t/problem-with-import-script-ipboard3-rb/151783/4 "2020-05-19T00:54:49Z")

</div>

> [@pfaffman](#):
>
> 这是因为调用时 `raw` 为 `nil`。
> 
> 因此，你需要找出是哪个函数在调用它，以及为什么它没有获取到帖子的原始数据。
> 
> 我猜问题出在这一行：
> 
> ```plaintext
> bio_raw: clean_up(u["pp_about_me"]),
> 
> ```
> 
> 如果是这样，那么或许可以修改 `clean_up` 函数，使其在没有数据时返回 `nil`。

这样写可以吗？

if raw.to\_i.zero?  
return  
end

我试过了，所有用户、主题和帖子都成功导入了，但帖子正文都是空的。你知道是什么原因吗？我觉得添加 “return nil” 可能不会有太大区别，你怎么看？  
另外，所有私信也都导入了，但内容也是空的。

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2020年五月19日 02:07 UTC](https://meta.discourse.org/t/problem-with-import-script-ipboard3-rb/151783/5 "2020-05-19T02:07:24Z")

</div>

数据库查询不知为何出错了。它无法获取帖子内容的数据。

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [2020年五月19日 06:55 UTC](https://meta.discourse.org/t/problem-with-import-script-ipboard3-rb/151783/6 "2020-05-19T06:55:15Z")

</div>

> [@dr3adx](#):
>
> 这样好吗？
> 
> if raw.to\_i.zero?  
> return  
> end

不，那样会触发得太频繁。试试这个：

`return if raw.nil?`

---

<div class="post-metadata">

### Author: ![dr3adx](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@dr3adx](https://meta.discourse.org/u/dr3adx)
#### Post date: [2020年五月19日 17:01 UTC](https://meta.discourse.org/t/problem-with-import-script-ipboard3-rb/151783/7 "2020-05-19T17:01:05Z")

</div>

> [@pfaffman](#):
>
> 数据库查询不知为何出错了。它无法获取帖子内容的数据。

这很奇怪，因为我使用的是 IPB3，并且我检查了列名，它们是对应的 😮

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2020年五月19日 17:36 UTC](https://meta.discourse.org/t/problem-with-import-script-ipboard3-rb/151783/8 "2020-05-19T17:36:26Z")

</div>

如果你执行脚本中使用的查询，它们是否返回了你所期望的数据？

你是否将

```plaintext
if raw.to_i.zero?

```

改为类似

```
if raw.length == 0

```

的形式？

`"randome text".to_i.zero?` 将始终为 true。

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2020年六月18日 17:51 UTC](https://meta.discourse.org/t/problem-with-import-script-ipboard3-rb/151783/9 "2020-06-18T17:51:42Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
