无法将图像解析为

无法将图像解析为

本文介绍了ActionView::Template::Error: 无法将图像解析为 URL:nil:NilClass 的未定义方法 `[]'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用:红宝石 2.4.0p0导轨 5.2.3在运行我的测试用例时:有和错误:

using:Ruby 2.4.0p0Rails 5.2.3while running my test cases: having and error:

我的测试用例是这样的:

My testcase is like:

require 'test_helper'

class SubscriptionsControllerTest < ActionDispatch::IntegrationTest

  test "Can reach to index " do
    get subscriptions_url
    assert_response :success
  end

结束

错误:

SubscriptionsControllerTest#test_Can_reach_to_index_:
ActionView::Template::Error: Can't resolve image into URL: undefined method `[]' for nil:NilClass
    app/views/subscriptions/index.html.erb:43:in `_app_views_subscriptions_index_html_erb__900758959545617488_70234463713200'
    test/controllers/subscriptions_controller_test.rb:6:in `block in <class:SubscriptionsControllerTest>'

但是手动打开用户界面时图像加载正确.你能提出什么问题吗?在视图中有 image_tag 作为第 43 行.

But the image load correctly when open the ui manually. could you suggest what is wrong.in the view has image_tag as on line no 43.

 <%= image_tag 'tukacad_1.png', alt: '', class: "img-responsive" %>

推荐答案

在 application.rb 或 test.rb 中写下一行

inside application.rb or test.rb write the following line

config.serve_static_assets = true

也运行

rails assets:precompile

这篇关于ActionView::Template::Error: 无法将图像解析为 URL:nil:NilClass 的未定义方法 `[]'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 01:43