如何在Rails项目5安装设计?

问题描述 投票:0回答:1

我已经添加了宝石“色器件”我的Gemfile。捆绑安装运行正常,但是当我运行rails generate devise:install,我得到这个错误。

lib/api_constraint.rb文件是RSpec的测试的辅助文件:

class ApiConstraints
  def initialize(options)
    @version = options[:version]
    @default = options[:default]
  end

  def matches?(req)
    @default || req.headers['Accept'].include?("application/vnd.marketplace.v#{@version}")
  end
end

和我的测试中色器件安装之前lib/api_constraints_spec.rb运行良好:

require 'spec_helper'
require './lib/api_constraints'

describe ApiConstraints do
  let(:api_constraints_v1) { ApiConstraints.new(version: 1) }
  let(:api_constraints_v2) { ApiConstraints.new(version: 2, default: true) }

  describe 'matches?' do
    it "returns true when the version matches the 'Accept' header" do
      request = double(host: 'api.marketplace.dev',
                       headers: { 'Accept' => 'application/vnd.marketplace.v1' })
      expect(api_constraints_v1.matches?(request)).to be_truthy
    end

    it "returns the default version when 'default' option is specified" do
      request = double(host: 'api.marketplace.dev')
      expect(api_constraints_v2.matches?(request)).to be_truthy
    end
  end
end

这是错误:

/home/tac/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:74:in `block in load_missing_constant': uninitialized constant ApiConstraints (NameError)
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:8:in `without_bootsnap_cache'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:74:in `rescue in load_missing_constant'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:56:in `load_missing_constant'
    from /home/tac/RubymineProjects/market_place_api/config/routes.rb:4:in `block (2 levels) in <main>'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/mapper.rb:948:in `block (2 levels) in namespace'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/mapper.rb:879:in `scope'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/mapper.rb:948:in `block in namespace'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/mapper.rb:1833:in `path_scope'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/mapper.rb:947:in `namespace'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/mapper.rb:1559:in `namespace'
    from /home/tac/RubymineProjects/market_place_api/config/routes.rb:3:in `block in <main>'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/route_set.rb:414:in `draw'
    from /home/tac/RubymineProjects/market_place_api/config/routes.rb:1:in `<main>'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:41:in `block in load_paths'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:41:in `each'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:41:in `load_paths'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:20:in `reload!'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:30:in `block in updater'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/activesupport-5.2.2/lib/active_support/file_update_checker.rb:83:in `execute'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:10:in `execute'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/railties-5.2.2/lib/rails/application/finisher.rb:130:in `block in <module:Finisher>'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `instance_exec'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `run'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/railties-5.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /home/tac/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
    from /home/tac/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /home/tac/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /home/tac/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /home/tac/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/tsort.rb:347:in `each'
    from /home/tac/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/tsort.rb:347:in `call'
    from /home/tac/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
    from /home/tac/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
    from /home/tac/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/railties-5.2.2/lib/rails/initializable.rb:60:in `run_initializers'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/railties-5.2.2/lib/rails/application.rb:361:in `initialize!'
    from /home/tac/RubymineProjects/market_place_api/config/environment.rb:5:in `<main>'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/application.rb:102:in `preload'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
    from /home/tac/.rvm/gems/ruby-2.6.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /home/tac/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /home/tac/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from -e:1:in `<main>'
ruby-on-rails ruby-on-rails-5
1个回答
1
投票

添加到您的application.rb

# Custom Auto-Load rb files
config.autoload_paths << Rails.root.join('lib')
config.eager_load_paths << Rails.root.join('lib')

并重新启动服务器

我只是克隆,并试图,它的工作原理

enter image description here

我改成PG创业板和中小改变Ruby和Rails版本,这不应该伤害依旧

© www.soinside.com 2019 - 2024. All rights reserved.