【问题标题】:ActionView::MissingTemplate errors on Travis CI (but not locally)Travis CI 上的 ActionView::MissingTemplate 错误(但不是本地)
【发布时间】:2015-04-24 18:26:44
【问题描述】:

解决方案

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

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

tl;博士

我的测试在本地通过并且应用程序似乎可以运行,但是我在一个控制器上的所有测试都失败了,出现 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 似乎都在那里。为什么特拉维斯找不到他们? (同样, bills_controller_test.rb 中的测试是唯一在 Travis 上失败的测试,它们在本地通过。)

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

我尝试过的

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

相关代码sn-ps

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

想法

  • 由于我刚刚将立法更改为比尔,我是否会对 Travis 存在某种缓存问题?
  • 这可能是我的 API 和默认命名空间之间的命名空间问题(我不这么认为,因为 Bills 是唯一的问题)
  • 我漏掉了一个错字吗?

【问题讨论】:

  • 这个问题是由无法再复制的问题或简单的印刷错误引起的。我投票决定将其关闭为题外话。因为它是 StackOverflow 规则。
  • 这不完全是印刷错误;这是一个大小写问题,但这个大小写问题是由 Git 处理文件夹跟踪的方式引起的。也就是说,如果它偏离主题,我也很乐意将其删除。

标签: ruby-on-rails ruby travis-ci


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-11
    • 2013-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多