我正在使用ActionText编辑一个段落,并且该段落在本地完美运行,但是当我将其部署到Heroku时,页面的格式为rich_text_area,即使我遵循了rails指南,也会抛出一个错误,提示未定义的方法rich_text_area_tag。我以为我需要在生产中配置Active Storage,但事实并非如此。
这是我在Heroku的日志中得到的信息:
ActionView::Template::Error (undefined method 'rich_text_area_tag' for #<#<Class> Did you mean? rich_text_area)
<%= f.label :something, class:'label' %>
<%= f.rich_text_area :something %>
Run Code Online (Sandbox Code Playgroud) 我正在开发我的第一个 Rails 6 应用程序,但是当我尝试在 nginx 服务器后面的开发环境中提供它时,我发现了这条消息
我尝试添加错误中提到的配置,config/environments/development.rb但config/application.rb它不起作用。
我使用的是rails 6.0.0,ruby 2.6.5,nginx 1.10.3
如果我访问http://localhost:3000(直接 puma URL),它就可以正常工作。但我想知道为什么我会收到此错误。
如果您使用 ActiveStorage 并且您有一个包含 N 个图像的页面,您会收到 N 个对 Rails 应用程序的额外请求(即 N 个重定向)。如果页面上有数十张图像,这意味着浪费大量服务器资源。
我知道重定向对签名 URL 很有用。但是我想知道为什么 Rails 不预先计算最终的签名 URL 并将其嵌入到 HTML 页面中......这样我们可以保持签名 URL/受保护文件的优势,而无需对 Rails 服务器进行 N 次额外调用。
是否可以直接在 HTML 中包含图像变体的最终 URL/预签名 URL(从而避免重定向)?否则,为什么不可能?
这个问题已经持续了很长一段时间了,直到今天,我仍然没有找到解决方案。我见过一些类似的问题,但不完全是我所经历的。
自从 Rails Active Storage 在 Rails 5 中推出以来,我一直在体验它,但由于这个特殊问题,我从未在生产中实际使用它。Rails 6 发布时解决的主要问题是,如果您对文件附件实施任何验证,记录将不会保存,但附件(blob)仍会被保存,并且如果您的验证是针对内容类型(例如,确保它是 JPEG 图像),然后您最终会得到无效的附件(例如,如果您上传了文本文件)。例如,如果您尝试使用 image_tag“显示”此附件,这可能会导致问题。Rails 6 通过仅在记录实际保存到数据库中时才保存附件来解决此问题。这对我来说只能解决一半的问题。
这是我仍然遇到的情况,尚未找到解决方案。
假设您有一个非常基本的设置。具有姓名、电子邮件和附加头像的 Person 模型
Class Person < ApplicationRecord
has_one_attached :avatar
#Check that image type is jpg or png
validate :check_image_type
#Remove avatar flag needed for form
attr_accessor :remove_avatar
#purge picture if remove picture flag was ticked on form
after_save :purge_avatar, if: :purge_requested?
#Returns a thumbnail version of the property picture
def thumbnail
return self.avatar.variant(resize:'100x100').processed
end
private
#Validates the image type being uploaded
def check_image_type …Run Code Online (Sandbox Code Playgroud) secret_key_base既然我们拥有每个环境的凭据,那么在 Rails 6上定义的正确方法是什么?
我的环境有这个变量,SECRET_KEY_BASE但 Rails 没有找到它。我尝试定义secret_key_base,config\credentials\production.yml.enc但它对Rails.application.credentials.secret_key_base
我知道config/secrets.yml有
staging:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
Run Code Online (Sandbox Code Playgroud)
有效,但是,那是 Rails 6 的方式吗?
我们有办法禁用操作文本的附件吗?类似于下面的 has_rich_text :content,attachment: false
这样,我们就可以从数据库中删除 active_storage_blobs、active_storage_attachments 表。在这种情况下,只有 action_text_rich_texts 表才能满足目的。
rich-text-editor rails-activestorage ruby-on-rails-6 actiontext
嗨,我最近开始使用 ruby 2.6.5 开发 Rails 6。由于 rails 6 引入了 webpack,所以我正在尝试使用 webpack 加载我的 js 文件。虽然我已经在 appliation.js 中需要 jquery,但我仍然收到以下错误:
'Uncaught ReferenceError: $ is not defined'
Run Code Online (Sandbox Code Playgroud)
应用程序.js
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require('packs/jquery')
Run Code Online (Sandbox Code Playgroud)
我的 'jquery.js' 文件位于 packs 目录中。如果我遗漏了什么,请告诉我。提前致谢 :)
我有一个 Rails 6 应用程序,它成功部署到 Heroku 并在 localhost:3000 上工作。
我通过yarn和webpack添加了tailwindcss。它在 localhost 上运行得很好,但不能在 heroku 上运行。当我运行时heroku logs出现以下错误
我已经阅读了所有 Heroku Rails 6 Webpacker 问题,并尝试了所有建议。没有任何效果。
<%= stylesheet_pack_tag %>......没有帮助 extract_css: true在 webpacker.yml 文件中切换了......没有帮助 heroku buildpacks:clear heroku buildpacks:set heroku/nodejs heroku buildpacks:add heroku/ruby
...没有帮助 有谁知道发生了什么?
我的 github 仓库是https://github.com/HundredBillion/enneagram
我曾尝试更改 bootstrap、jquery 和 popper 的版本,但没有成功。我不认为我使用了多个版本的 jquery。不知道哪里出错了。如果有人能帮我找到我遗漏的东西,那就太好了。
这是我的文件列表,
包.json:
{
"name": "kf",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-free": "^5.12.1",
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "4.2.2",
"bootstrap": "^4.4.1",
"jquery": "^3.4.1",
"popper.js": "^1.16.1",
"sweetalert2": "^9.8.2"
},
"version": "0.1.0",
"devDependencies": {
"webpack-dev-server": "^3.10.3"
}
}
Run Code Online (Sandbox Code Playgroud)
配置/webpack/environment.js
const { environment } = require('@rails/webpacker');
const webpack = require('webpack');
environment.plugins.append(
'Provide',
new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery',
Popper: ['popper.js', 'default']
})
);
module.exports = environment;
Run Code Online (Sandbox Code Playgroud)
应用程序.js
require('@rails/ujs').start();
require('jquery/dist/jquery');
require('popper.js/dist/umd/popper');
require('bootstrap/dist/js/bootstrap');
require('@fortawesome/fontawesome-free');
require('./owl.carousel.min');
require('./fastclick');
require('./custom-script');
require('./return-to-top');
const Swal = require('sweetalert2');
window.Swal …Run Code Online (Sandbox Code Playgroud) 我正在尝试填写 ActionText rich_text 字段表单输入,但不知道如何选择它。我正在使用 Rails 6 和 ActionText。
和
class Activity
has_rich_text :description
end
Run Code Online (Sandbox Code Playgroud)
和 _form.rb
= f.label :description
= f.rich_text_area :description, class: 'form-control'
Run Code Online (Sandbox Code Playgroud)
测试使用:
fill_in "Description", with: "Some description.."
Run Code Online (Sandbox Code Playgroud)
我会得到错误
Capybara::ElementNotFound: Unable to find field "Description" that is not disabled
Run Code Online (Sandbox Code Playgroud)
我怀疑问题在于 Trix 编辑器如何在您键入时动态填充此字段。我只是不确定如何进行输入,复制用户输入文本的方式。
ruby-on-rails-6 ×10
actiontext ×2
heroku ×2
javascript ×2
jquery ×2
ruby ×2
webpack ×2
amazon-s3 ×1
bootstrap-4 ×1
nginx ×1
tailwind-css ×1
webpacker ×1
yarnpkg ×1