未定义的方法'+'错误 Rails、Net/http

发布于 2025-01-03 07:39:32 字数 376 浏览 0 评论 0原文

实际上问题不在于“+”号。但我对此表示怀疑,因为它是该页面中唯一的“+”符号。

导致错误的行是“- res = req.request_head(imageurl.path)” 我的代码:

- req = Net::HTTP.new(imageurl.host, imageurl.port)
- res = req.request_head(imageurl.path)

抛出错误“ActionView::Template::Error (undefined method `+' for nil:NilClass):” 有什么问题吗?

非常感谢您的所有帮助&对于造成的不便,我们深表歉意。

但问题仍然没有解决。

Actually the problem was not with the '+' sign. But i doubted it because, it was the only '+' sign in that page.

The line which causes the error is "- res = req.request_head(imageurl.path)"
My code:

- req = Net::HTTP.new(imageurl.host, imageurl.port)
- res = req.request_head(imageurl.path)

throws the error "ActionView::Template::Error (undefined method `+' for nil:NilClass):"
what is the issue?

Thanks a lot for all the helps & sorry for the inconveniences caused.

But the issue is still not fixed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情深已缘浅 2025-01-10 07:39:32

你可以使用标准的 ruby​​ 方法以更优雅的方式实现你想要的,例如:

- products.shuffle.each_with_index do |product, i|
  - if i == 24                              
    %li.product                  
      .image{:style => "width:180px;"}

如果你需要在每 25 个产品之后使用 li,你可以使用 each_slice

- products.shuffle.each_slice(25) do |items|
  %li.product                  
    .image{:style => "width:180px;"}

虽然它是不是你问题的答案(其他答案应该适合你),但这种方法更红利。

You can use standard ruby methods to achieve what you want in more elegant way, for example:

- products.shuffle.each_with_index do |product, i|
  - if i == 24                              
    %li.product                  
      .image{:style => "width:180px;"}

If you need that li after each 25th product, you can use each_slice:

- products.shuffle.each_slice(25) do |items|
  %li.product                  
    .image{:style => "width:180px;"}

Though it's not an answer to your question (other answers should work for you), but this approach is more rubiest.

甩你一脸翔 2025-01-10 07:39:32

看起来名为 scount 的对象上的方法 to_i 返回 nil。对我来说下一步似乎是调查 scount 的类。

在下面的评论后更新一些代码;

- scount = 1
- products.shuffle.each do |product|
  - if scount == 25                              
    %li.product                  
      .image{:style => "width:180px;"}
  - scount += 1

It seems that the method to_i on the object called scount is returning nil. An investigation into what the class of scount may be seems like the next step to me.

Update with some code after comments below;

- scount = 1
- products.shuffle.each do |product|
  - if scount == 25                              
    %li.product                  
      .image{:style => "width:180px;"}
  - scount += 1
↙温凉少女 2025-01-10 07:39:32

下面应该可以工作 -

- products.shuffle.each do |product|
  scount = defined?(scount) ? scount.to_i : 0
  scount += 1
  - if scount == 25                              
   %li.product                  
    .image{:style => "width:180px;"}

Below should work -

- products.shuffle.each do |product|
  scount = defined?(scount) ? scount.to_i : 0
  scount += 1
  - if scount == 25                              
   %li.product                  
    .image{:style => "width:180px;"}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文