gpt4 book ai didi

ruby-on-rails - Travis CI 上的 ActionView::MissingTemplate 错误(但不是本地)

转载 作者:数据小太阳 更新时间:2023-10-29 07:59:28 24 4
gpt4 key购买 nike

解决方案

这是一个愚蠢的。 Git 有时对文件夹的行为很奇怪;更改文件夹名称不是被推送的更改。在 GitHub 上,我的 View 文件夹是大写 B 的“Bills”,即使它在本地是“bills”。

我通过重命名我的旧文件夹,创建一个新的“bills”文件夹,然后将内容从旧文件夹移动到新文件夹来解决这个问题(因为移动文件是一个可推送的更改)。参见 this更多细节。

tl;dr

我的测试在本地通过并且应用程序似乎可以运行,但是我在一个 Controller 上的所有测试都失败并出现 ActionView::MissingTemplate 错误,尽管模板似乎位于正确的位置。知道为什么吗?

问题

我刚刚花了一个下午重构一个 Rails 应用程序(最值得注意的是,将 Legislation 重命名为 Bill),但我现在遇到了一个我无法弄清楚的构建问题。

当我在本地运行我的测试时,它们都通过了,并且在应用程序周围单击按预期工作。但是,在 Travis CI 上,我的 bills_controller_test.rb 中的所有内容都出现此错误 (ActionView::MissingTemplate):

Error:
BillsControllerTest#test_: bills should get index. :
ActionView::MissingTemplate: Missing template bills/index, application/index with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :prawn, :coffee, :jbuilder]}. Searched in:
* "/home/travis/build/troy-open-data/legislative_twitter/app/views"
* "/home/travis/build/troy-open-data/legislative_twitter/vendor/bundle/ruby/2.2.0/gems/kaminari-0.16.3/app/views"
* "/home/travis/build/troy-open-data/legislative_twitter/vendor/bundle/ruby/2.2.0/gems/foundation-rails-5.5.1.0/app/views"
test/controllers/bills_controller_test.rb:6:in `block (2 levels) in <class:BillsControllerTest>'

( On Travis )

但是,文件 app/views/bills/*.html.erb对于每个 Controller Action 似乎都在那里。为什么特拉维斯找不到他们? (同样,bills_controller_test.rb 中的测试是唯一在 Travis 上失败的测试,它们在本地通过。)

我无法在本地复制它,到目前为止,我在谷歌上搜索和摆弄它都没有成功。

我尝试过的

  • 我仔细检查了所有对 bill 的引用是否具有正确的复数形式和大写形式(它们似乎是)——这是我的第一个猜测,因为 OS X 和 Linux 有时对大写形式的处理方式不同。
  • 我检查了其他编辑,特别是对 .travis.yml 和 test_helper.rb 的配置更改,但似乎都没有引起问题。
  • 我已经确认 bills_controller_test.rb 实际上正在连接到 app/controllers/bills_controller.rb,并且它是(错误出现在 Controller 操作结束时的 render: :<action> 上)

相关代码片段

test/controllers/bills_controller_test.rb(#index)(on GitHub)

require 'test_helper'

class BillsControllerTest < ActionController::TestCase
context 'bills' do
should 'get index' do
get :index
assert_response :success
assert_not_nil assigns(:bills)
end
...
end
...
end

app/controllers/bills_controller.rb (#index) ( on GitHub )

class BillsController < ApplicationController
before_action :set_bill, only: [:show, :edit, :update, :destroy]

# GET /bills
def index
@bills = Bill.by_recent
.includes(:attachments)
.page(params[:page])
end
...
end

routes.rb ( on GitHub )

require 'api_version'  # lib/api_version.rb

Rails.application.routes.draw do
namespace :api, defaults: { format: 'json' } do
scope module: :v1, constraints: ApiVersion.new('v1', true) do
resources :bills, only: [:index, :show]
resources :meetings, only: [:index, :show]
scope '/meetings/:id' do
get '/agenda', to: 'meetings#agenda', as: 'agenda'
get '/minutes', to: 'meetings#minutes', as: 'minutes'
end
resources :organizations, only: [:index, :show]
root to: 'data#index'
end
end


resources :bills
resources :organizations
resources :meetings
scope '/meetings/:id' do
get '/agenda', to: 'meetings#agenda', as: 'agenda'
get '/minutes', to: 'meetings#minutes', as: 'minutes'
get '/in_progress', to: 'meetings#start_meeting', as: 'start_meeting'
get '/agenda/toggle', to: 'meetings#toggle_agenda', as: 'toggle_agenda'
get '/minutes/toggle', to: 'meetings#toggle_minutes', as: 'toggle_minutes'
end
get 'search', to: 'search#index', as: 'search'
post 'versions/:id/revert', to: 'versions#revert', as: 'revert_version'

root 'meetings#index'
end

想法

  • 自从我刚刚将 Legislation 更改为 Bill 后,Travis 是否存在某种缓存问题?
  • 这会不会是我的 API 和默认命名空间之间的命名空间问题(我不这么认为,因为 Bills 是唯一的问题)
  • 有没有我遗漏的拼写错误?

最佳答案

我发帖后就想通了。为什么这不能在几个小时前发生? :( 我会留下这个问题,以防其他人遇到同样的问题。

Git 不像跟踪文件那样跟踪文件夹。我检查了 GitHub 上的存储库, View 位于/app/views/Bills 下;我想当我在重构期间更改它时,它没有被推送,因为它是一个文件夹。

我通过将本地文件重命名为 Bills 并将所有内容从 Bills(旧文件夹)移动到 bills(新文件夹)来修复它。 ( more detail )

关于ruby-on-rails - Travis CI 上的 ActionView::MissingTemplate 错误(但不是本地),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29854887/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com