![](/img/trans.png)
[英]Rails 6.0 action text couldn't find file 'trix/dist/trix' with type 'text/css'
[英]Action text (Trix) : cannot add images in rich text on Rails (“attach files” not saved)
我正在向我的 Rails 6.0 網站添加一個博客。
我已安裝Action Text並將 Active Storage 鏈接到 Cloudinary
然后我創建了一個帶有照片的文章 model。
class Article < ApplicationRecord
has_one_attached :photo
has_rich_text :rich_body
validates :title, uniqueness: true
validates :lead, presence: true
validates :rich_body, presence: true
end
在 Articles/new.html.erb 上,我為“rich_body”添加了 Trix 所見即所得編輯器。
<div class="container">
<%= simple_form_for(@article) do |f| %>
<div class="form-inputs">
<%= f.input :title %>
<%= f.input :lead %>
<%= f.input :photo, as: :file %>
<%= f.input :caption %>
</div>
<div class="form-inputs">
<%= f.rich_text_area :rich_body %>
</div>
<div class="form-actions">
<%= f.button :submit, class: "btn btn-primary" %>
</div>
<% end %>
</div>
我設法創建了通過“照片”字段上傳圖像的博客文章。
現在我想在rich_body 中添加圖像。 我看這篇文章是為了這樣做。 我用“附加文件”附加它們(參見 thsi 按鈕的屏幕截圖)。 它顯示在編輯器中(見截圖)
當我點擊保存時,文章就創建好了。 但只剩下“rich_body”的文本。 沒有附加圖像。 如果我查看“參數”,則沒有圖像的痕跡。
=> <ActionController::Parameters {"utf8"=>"✓", "authenticity_token"=>"DDGTxfT/aSoY5I5FNMrzv+hJ+seNlce0sJufFBREfUBlETeLGjejbnoxq2jhyzwGcZe1UAbCJbozi1O4vH5GyQ==", "article"=><ActionController::Parameters {"title"=>"Post title", "lead"=>"Summary or the post", "photo"=>#<ActionDispatch::Http::UploadedFile:0x00008b18957b5az8 @tempfile=#<Tempfile:/tmp/RackMultipart20210122-9530-1nu0w1w.jpg>, @original_filename="tools.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"article[photo]\"; filename=\"tools.jpg\"\r\nContent-Type: image/jpeg\r\n">, "caption"=>"This is the caption of the photo", "rich_body"=>"<div>Some text. The attached image is below.<br><br>The attached image is above<br><br></div>"} permitted: false>, "commit"=>"Créer un(e) Article", "controller"=>"articles", "action"=>"create"} permitted: false>
知道我缺少什么嗎?
非常感謝您的幫助。
格雷戈里
你在使用ActiveStorage
嗎?
應該運行命令來創建必要的表:
bundle exec rails active_storage:install
bundle exec rails db:migrate
檢查以確保您有兩個表active_storage_blobs
和active_storage_attachments
。
我知道這很舊,但有一個與此類似的問題,可能與 S3 存儲桶上的 CORS 有關。 https://github.com/rails/rails/issues/36982#issuecomment-636330624
我遇到了同樣的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.