有没有人解决这个问题Ruby 2.7.0?
我使用rbenv并安装了 Ruby v2.7.0,然后使用Rails v6.0.2.1.
目前,通过运行其中之一
rails s
rails s -u puma
rails s -u webrick
Run Code Online (Sandbox Code Playgroud)
服务器已启动并且站点已提供服务,但在Console日志中我看到两条警告消息:
local:~/rcode/rb27$ rails s
=> Booting Puma
=> Rails 6.0.2.1 application starting in development
=> Run `rails server --help` for more startup options
.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/static.rb:110: warning: The called method `initialize' is defined here
Puma starting in single …Run Code Online (Sandbox Code Playgroud) 今天我尝试为我的 rails 6.1.0 构建一个带有活动存储的 docker,我收到以下错误:
Your bundle is locked to mimemagic (0.3.5), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of mimemagic (0.3.5) has removed it. You'll need to update your
bundle to a version other than mimemagic (0.3.5) that hasn't been removed in order to install.
Run Code Online (Sandbox Code Playgroud)
现在我尝试安装 mimemagic
gem install mimemagic -v 0.3.5
Run Code Online (Sandbox Code Playgroud)
我有以下错误:
ERROR: Could not find a valid gem 'mimemagic' …Run Code Online (Sandbox Code Playgroud) 我正在根据“Rails 入门”创建一个新的 Rails 应用程序。应用程序在步骤 4.1 中正常启动。但是当我创建我的第一个控制器时,我有一个 webpack 错误。
我是 webpack 的新手,我的所有文档都是红色的,但我不明白有什么问题或遗漏了什么......
rails webpacker:install
identical config/webpacker.yml
Copying webpack core config
exist config/webpack
identical config/webpack/development.js
identical config/webpack/environment.js
identical config/webpack/production.js
identical config/webpack/test.js
Copying postcss.config.js to app root directory
identical postcss.config.js
Copying babel.config.js to app root directory
identical babel.config.js
Copying .browserslistrc to app root directory
identical .browserslistrc
The JavaScript app source directory already exists
apply C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/webpacker-4.0.7/lib/install/binstubs.rb
Copying binstubs
exist bin
identical bin/webpack
identical bin/webpack-dev-server
append …Run Code Online (Sandbox Code Playgroud) 在开发/测试时,我的控制台中不断出现此错误
Warning: the running version of Bundler (2.1.2) is older than the version that created the lockfile (2.1.4). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.1.4`.
Run Code Online (Sandbox Code Playgroud)
它根本没有阻止我,而是在打扰我。我知道最简单的解决方案就是将我的 Gemfile.lock 更新为这个。
BUNDLED WITH
2.1.2
Run Code Online (Sandbox Code Playgroud)
但我想永久解决这个问题。我试着
gem uninstall bundler
Run Code Online (Sandbox Code Playgroud)
进而
gem install bundler -v 2.1.4
Run Code Online (Sandbox Code Playgroud)
它让我一直给这个错误
Gem bundler-2.1.2 cannot be uninstalled because it is a default gem
Run Code Online (Sandbox Code Playgroud)
当我尝试首先安装 2.1.4 然后删除 bundler 2.1.2 控制台给我这个输出。
Gem bundler-2.1.2 cannot be uninstalled because it is a default gem …Run Code Online (Sandbox Code Playgroud) 从 Rails 5 升级到 6.1 后,ActiveStorage 引发错误:
unknown attribute 'service_name' for ActiveStorage::Blob.
为什么,我该如何解决?
我的问题与使用 Rails 3.1相同,您将“特定于页面的”JavaScript 代码放在哪里?,仅适用于 Rails 6 而不是 Rails 3.1。
假设我有一些 JavaScript 想要用于我的帖子索引页面。我把那个文件放在哪里,我如何包含它?
在上一个问题中,答案通常使用 Rails Asset Pipeline。但是,对于 Rails 6,我的理解是它使用 webpacker 而不是 JavaScript 文件的 Asset Pipeline。
注意:我不希望始终包含该文件。例如。如果我在作者索引页上,我不希望包含帖子索引页的 JavaScript 文件。为什么?想象一下,我$('li').on('click', changeColor);在 JS 文件中拥有帖子索引页面。我可能不希望该代码在作者索引页上运行,但如果包含该文件,它就会运行。您可以通过命名空间来解决这个问题,但我认为不包含不必要的文件会更干净(并且性能更高)。
当使用 Rails 6 创建一个新的 rails 项目时,它会创建一个带有 stylesheet_link_tag 的 application.html.erb 来为 javascript 文件加载 CSS 和 javascript_pack_tag。
现在,rails 6 还提供了一个 stylesheet_pack_tag,所以我的问题是,什么时候使用它?如果我们使用它,我们是否需要在 app/javascript 文件夹中添加所有 CSS 文件?
使用 rails 6 和 webpacker 加载 css、图像的最佳实践是什么?
我目前正在尝试将Rails 6.0.0.rc1的默认javascript文件夹从app/assets/javascript移到app/javascript。该application.js文件现在位于中app/javascript/packs。现在,我想添加几个js文件,但是由于某种原因,它们没有被导入,并且我找不到关于如何在Rails 6中完成此操作的任何文档。我尝试了一些方法:
custom_js在下创建一个新文件夹app/javascript/packs,将所有我的js文件放在其中,然后将添加require "custom_js"到application.js。
复制下我所有的js文件app/javascript/channels(这应该是默认包括在内,因为application.js有require("channels"))。
添加require_tree .到application.js,这是以前的方法。
如何在Rails 6应用程序中加载自己的js文件?
将应用程序 Rails 5.2 更新为 6,更新添加了以下两个迁移:
# This migration comes from active_storage (originally 20190112182829)
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
def up
unless column_exists?(:active_storage_blobs, :service_name)
add_column :active_storage_blobs, :service_name, :string
if configured_service = ActiveStorage::Blob.service.name
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
end
change_column :active_storage_blobs, :service_name, :string, null: false
end
end
end
Run Code Online (Sandbox Code Playgroud)
和
# This migration comes from active_storage (originally 20191206030411)
class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
def up
create_table :active_storage_variant_records do |t|
t.belongs_to :blob, null: false, index: false
t.string :variation_digest, null: false
t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true …Run Code Online (Sandbox Code Playgroud) 我发誓我已经阅读了文档,并且我认为我对这些原理有了基本的了解,但是我一生都无法弄清楚我在哪里不恰当地加载了这些常量。
我正在升级一个最初是 Rails 5.2 的应用程序
当我运行 RSpec、服务器、本地控制台等时,我收到此警告。
DEPRECATION WARNING: Initialization autoloaded the constants ApplicationHelper, EventsHelper, FontAwesome::Rails::IconHelper, DeviseHelper, ErrorHandler, and ApplicationController.
Being able to do this is deprecated. Autoloading during initialization is going
to be an error condition in future versions of Rails.
Run Code Online (Sandbox Code Playgroud)
以下是不正确自动加载的常量:
我寻找过可能调用这些常量的实例include,require但没有找到。我特别关注我的初始化程序。
我已经运行(并通读)bin/rails zeitwerk:check没有任何明显的提示。我看到这些实例按预期加载:
... …Run Code Online (Sandbox Code Playgroud)