标签: actiontext

将按钮添加到 Rails ActionText 工具栏

配置 ActionText 以向工具栏添加按钮的最佳方法是什么。例如,一个 h2 和 h3 按钮?

ruby-on-rails actiontext

10
推荐指数
2
解决办法
3063
查看次数

在没有 webpack 的情况下使用 ActionText

我尝试在 Rails 6 上使用旧方式资产管道(没有 Webpack)来实现 ActionTest

几乎一切都很好,除了加载@rails/actiontext

在我的 application.js 中我有

//= require trix
//= require @rails/actiontext
Run Code Online (Sandbox Code Playgroud)

Riche编辑器出现,我可以更改粗体/斜体文本,但无法添加图像(未上传)

我有一个 JS 错误:未捕获的语法错误:无法在模块外使用 import 语句

在线:从actiontext中的attachment_uplaod.js的“./attachment_upload”导入{AttachmentUpload}。

没有 webpack 有什么方法可以实现这一点吗?

谢谢

ruby-on-rails asset-pipeline actiontext

9
推荐指数
1
解决办法
1371
查看次数

Rails 6 ActionText在Heroku上不起作用(未定义的方法'rich_text_area_tag')

我正在使用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)

ruby-on-rails heroku ruby-on-rails-6 actiontext

8
推荐指数
1
解决办法
294
查看次数

有什么办法可以在 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

8
推荐指数
2
解决办法
1517
查看次数

如何使用 RSpec 测试 ActionText?

我正在尝试编写一个 RSpec 系统测试,该测试涉及在页面上填写 ActionText / Trix 字段。

似乎此处ActionText::SystemTestHelper定义的可用于帮助完成此任务,但到目前为止我还没有成功实现它。

我的 RSpec 测试如下所示:

# spec/system/add_job_posting_spec.rb

require 'rails_helper'

RSpec.describe 'adding a job posting', type: :system do
  let(:user) { FactoryBot.create :user }

  before do
    login_as(user)
    visit new_job_posting_path
  end

  context 'with valid information' do
    let(:valid_job_posting) { FactoryBot.create :job_posting }

    scenario 'creates a job posting', js: true do
      fill_in 'Title', with: valid_job_posting.title
      fill_in_rich_text_area 'Description', with: 'Job Info'

      click_button 'Submit'
      expect(page).to have_content 'Job was successfully created.'
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我还尝试创建一个 RSpec 支持文件

# spec/support/action_text.rb …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails trix ruby-on-rails-6 actiontext

7
推荐指数
2
解决办法
1034
查看次数

如何在 Ruby on Rails 上嵌入带有 ActionText/Trix 的 iframe?

我找不到实现嵌入 youtube/vimeo 视频的功能的方法是 actiontext/trix。

这就是我想要实现的目标:

在此处输入图片说明

GIF 来源:https : //github.com/basecamp/trix/issues/206#issuecomment-198479999

我查看了所有类似的问题/解决方案,但似乎没有任何答案:

我们如何使用 Ruby on Rails 使用 actiontext/trix 正确嵌入 iframe?

ruby-on-rails trix actiontext

7
推荐指数
1
解决办法
1179
查看次数

弃用警告:初始化自动加载常量 ActionText::ContentHelper 和 ActionText::TagHelper

我试图理解弃用警告:

DEPRECATION WARNING: Initialization autoloaded the constants 
ActionText::ContentHelper and ActionText::TagHelper.

Being able to do this is deprecated. Autoloading during initialization is 
going
to be an error condition in future versions of Rails.

Reloading does not reboot the application, and therefore code executed during
initialization does not run again. So, if you reload 
ActionText::ContentHelper, for example,
the expected changes won't be reflected in that stale Module object.

These autoloaded constants have been unloaded.

In order to autoload safely at boot time, …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails ruby-on-rails-6 actiontext

7
推荐指数
1
解决办法
4430
查看次数

无法将图像解析为 URL:#&lt;ActiveStorage::VariantWithRecord 的未定义方法“to_model”

根据我添加action_text/trix到我的 Rails 应用程序的文档。当我更新内容时。它向我显示以下错误。任何想法?

Showing /home/dell/code/tm/app/views/active_storage/blobs/_blob.html.erb where line #3 raised:

Can't resolve image into URL: undefined method `to_model' for #<ActiveStorage::VariantWithRecord:0x0000559255e1be40 @blob=#<ActiveStorage::Blob id: 12, key: "n48e43looijem16cdq5d48sqhu4d", filename: "Screenshot from 2021-08-28 17-10-25.png", content_type: "image/png", metadata: {}, service_name: "local", byte_size: 93757, checksum: "up8PwkoYwf+Y6NTRJvbAUA==", created_at: "2021-08-29 12:13:04.912555000 +0800">, @variation=#<ActiveStorage::Variation:0x0000559255e248d8 @transformations={:format=>"png", :resize_to_limit=>[1024, 768]}>>
Did you mean?  to_yaml

ActionView::Template::Error (Can't resolve image into URL: undefined method `to_model' for #<ActiveStorage::VariantWithRecord:0x0000559255e1be40 @blob=#<ActiveStorage::Blob id: 12, key: "n48e43looijem16cdq5d48sqhu4d", filename: "Screenshot from 2021-08-28 17-10-25.png", content_type: "image/png", metadata: {}, service_name: "local", …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails trix actiontext

7
推荐指数
1
解决办法
2015
查看次数

使用 ActionText 时转换回纯文本

首先让我说我喜欢 Rails 6 在 ActionText 中提供的功能。不幸的是,当我为类似 post 模型的属性声明它时:

class Post < ApplicationRecord
  has_rich_text :body
end
Run Code Online (Sandbox Code Playgroud)

我无法再访问正文。它成为一个 ActionText 实例。我完全理解这就是此功能的工作原理,但有时我需要将正文的纯文本传递给其他外部方法。在我的例子中,我在我的元描述标签中使用了 body 和一个叫做 meta-tags 的 gem。这样做会导致此错误:

Expected a string or an object that implements #to_str
Run Code Online (Sandbox Code Playgroud)

这是因为在纯文本列变成 AT 实例之前的内容:

=> #<ActionText::RichText id: 39, name: "body", body: #<ActionText::Content "<div class=\"trix-conte...">, record_type: "Post", record_id: 161, created_at: "2019-08-17 17:34:27", updated_at: "2019-08-17 17:34:27"> 
Run Code Online (Sandbox Code Playgroud)

看到它附带了 getter 方法,我尝试做类似的事情,@post.body.body但这实际上是

=> #<ActionText::Content "<div class=\"trix-conte...">
Run Code Online (Sandbox Code Playgroud)

另请注意,我已尝试在 post 模型中创建一个方法,但是一旦声明了 has_rich_text,我就不再具有对正文文本的原始访问权限。

我不确定如何:

  • 从 body 属性中提取我的原始内容将其转换为没有 html 的纯文本

ruby-on-rails ruby-on-rails-6 actiontext

6
推荐指数
1
解决办法
2781
查看次数

现有文本字段的 Rails 操作文本

我正在将我的一个新闻应用程序升级到 Rails 6.0.0。在解决问题时,我在使用富文本时遇到了问题。我的应用程序指向富文本正文字段而不是我现有的表格正文字段。

是否可以将现有的表格文本字段用于富文本,以便我可以在需要时编辑内容。对于新帖子,我可以使用 action_text_rich_texts 表,但对于现有帖子,我想使用现有表正文字段。

ruby ruby-on-rails-6 actiontext

6
推荐指数
2
解决办法
768
查看次数