【问题标题】:ActionController::RoutingError (No route matches [GET] "/javascripts/application.js")ActionController::RoutingError (没有路由匹配 [GET] "/javascripts/application.js")
【发布时间】:2019-03-01 13:28:25
【问题描述】:

我目前正在开发一个通过 webpacker 安装了 Vue 的 Rails 5.2 应用程序。但是,我没有做任何造型。我只是设置身份验证。当我转到users/sign_out 时,出现以下错误。

ActionController::RoutingError(没有路由匹配 [GET] “/javascripts/application.js”):

我在/javascripts/application.js 中确实有一个文件,其中包含以下代码:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require activestorage
//= require_tree .

不确定问题出在哪里。

<head>
    <title>ArtsySpace</title>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>

    <%= stylesheet_link_tag    'application', media: 'all' %>
    <%= javascript_include_tag 'application' %>
  </head>

environments/development.rb/

Rails.application.configure do
  # Verifies that versions and hashed value of the package contents in the project's package.json
  config.webpacker.check_yarn_integrity = true
  # Settings specified here will take precedence over those in config/application.rb.

  config.cache_classes = false

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports.
  config.consider_all_requests_local = true

  config.assets.debug = false
  # Enable/disable caching. By default caching is disabled.
  # Run rails dev:cache to toggle caching.
  if Rails.root.join('tmp', 'caching-dev.txt').exist?
    config.action_controller.perform_caching = true

    config.cache_store = :memory_store
    config.public_file_server.headers = {
      'Cache-Control' => "public, max-age=#{2.days.to_i}"
    }
  else
    config.action_controller.perform_caching = false

    config.cache_store = :null_store
  end

  # Store uploaded files on the local file system (see config/storage.yml for options)
  config.active_storage.service = :local

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations.
  config.active_record.migration_error = :page_load

  # Highlight code that triggered database queries in logs.
  config.active_record.verbose_query_logs = true

  config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

  config.webpacker.check_yarn_integrity = false


  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true

  # Use an evented file watcher to asynchronously detect changes in source code,
  # routes, locales, etc. This feature depends on the listen gem.
  config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end

【问题讨论】:

    标签: javascript routes ruby-on-rails-5 asset-pipeline


    【解决方案1】:

    这是旧的,但对于遇到此问题的任何人,您需要更改: &lt;%= javascript_include_tag 'application' %&gt;&lt;%= javascript_pack_tag 'application' %&gt;

    【讨论】:

    • 你能解释一下这有什么变化吗?更改后我收到undefined method 'javascript_pack_tag'
    • @Smartens 如果您已升级到 Rails 6,这将“激活”您的 webpack 安装并指示 rails 使用 webpack 而不是资产管道
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-21
    相关资源
    最近更新 更多