コントローラのテストを実行中に問題が発生しました。私は取得していますエラーが不足しているテンプレートです:ActionView :: MissingTemplate:js.erbファイルのテンプレートがありません
......code....
get 'security' => 'vulnerabilities#vulnerabilities_per_version', as: :vulnerabilities, defaults: { format: 'js' }
......code.....
あなたが見ることができるように、私は明らかにのみJSを受け入れるようにフォーマットを作り上げていますし、呼び出しは次のとおりです。ここで
ActionView::MissingTemplate Missing template vulnerabilities/vulnerabilities_per_version, application/vulnerabilities_per_version
with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :arb, :haml, :jbuilder]}
は私routes.rb
ファイルです実際にログにはJS
というメッセージが届きます。ここで
はコントローラです:
class VulnerabilitiesController < ApplicationController
def vulnerabilities_per_version
@release_versions = @releases.map(&:version).to_json
end
end
そしてここでは、私の見解である。ここでは
app/views/vulnerabilities/vulnerabilities_per_version.js.erb
$(function() {
$('#vulnerabilities').highcharts({
chart: {
type: 'column',
events: {
load: function() {
this.renderer.image('http://i64.tinypic.com/25irqt5.png', 60, 30, 280, 30)
.add();
}
}
},
credits: {
enabled: false
},
title: {
....code....
は私のコントローラのテストです:
require 'test_helper'
class VulnerabilitiesControllerTest < ActionController::TestCase
it 'should retrieve the 10 most recent releases for a project' do
@project = create(:project)
@project.project_security_sets << create(:project_security_set)
@project.project_security_sets[0].releases << create_list(:release, 10)
@project.project_security_sets[0].releases.each do |r|
r.vulnerabilities << create(:vulnerability)
end
@project.update!(best_project_security_set_id: @project.project_security_sets[0].id, editor_account: create(:admin))
get :vulnerabilities_per_version, id: @project.id, xhr: true
assert_response :success
assert_equal 10, @project.best_project_security_set.releases.count
assert_equal @project.best_project_security_set.releases.order(released_on: :asc), assigns(:releases)
end
end
私が働いてきたので、それはしばらくしていますjavascriptファイルをレンダリングすると、必要なコンポーネントが用意されているはずです。
私はjsとしてリクエストを受け取りました。応答は受け入れられ、js.erb
ファイルからハイチャートをレンダリングすることができます。私はrespond_to
ブロックを試しましたが、エラーが200
から404
に変更されたため、どこにでもいないようでした。何か不足していますか?