【发布时间】:2021-11-11 20:23:28
【问题描述】:
我遇到了一个奇怪的问题。
我最近在我的 Rails 应用程序中安装了 Trix。一切都很顺利,直到我尝试发布一篇博文并发现诸如 strong> 和 div> 之类的 html 元素作为实际文本包含在内(因此没有出现任何样式)。
还有其他人遇到过这个问题吗?我很确定我的设置与this
非常相似这是描述我的观点的图片:
为了清楚起见,图片是用户将看到的其中一张卡片的放大屏幕截图(因此应该设置样式......在实际视图中不输出 html)
这是我的设置
actiontext.scss
@import "trix/dist/trix";
.trix-content {
.attachment-gallery {
> action-text-attachment,
> .attachment {
flex: 1 0 33%;
padding: 0 0.5em;
max-width: 33%;
}
&.attachment-gallery--2,
&.attachment-gallery--4 {
> action-text-attachment,
> .attachment {
flex-basis: 50%;
max-width: 50%;
}
}
}
action-text-attachment {
.attachment {
padding: 0 !important;
max-width: 100% !important;
}
}
}
应用程序.scss
@import "actiontext";
我的 new.html.erb 中的样式有效,但发布时未显示上述样式。
继续
我的表格, new.html.erb
<div class="page-content-area">
<h1>Create a Blogpost</h1>
<h2>Fill in the details below</h2>
<%= simple_form_for [@blogposts] do |f| %>
<%= f.input :blog_title,
required: true,
autofocus: true,
input_html: { autocomplete: "Blogpost Title" }%>
<%= f.input :blog_sub_heading,
required: true,
autofocus: true,
input_html: { autocomplete: "Blogpost Sub Heading" }%>
<%= f.input :blog_text,
as: :rich_text_area,
required: true,
autofocus: true,
input_html: { class: "text-area-blog", autocomplete: "Blog Text" }%>
<%= f.input :photo,
autofocus: true,
as: :file %>
<%= f.submit "CREATE", class: "btn btn-primary" %>
<% end %>
</div>
应用程序.js
require("trix")
require("@rails/actiontext")
博文控制器
def new
@blogposts = Blogpost.new
end
def create
@blogposts = Blogpost.new(blogpost_params)
@blogposts.user = current_user
if @blogposts.save!
redirect_to blogpost_path(@blogposts)
else
render 'new'
end
end
private
def blogpost_params
params.require(:blogpost).permit(:user_id, :blog_title, :blog_sub_heading, :blog_text, :photo, :content)
end
博文模型
class Blogpost < ApplicationRecord
belongs_to :user
has_rich_text :content
end
如果您需要我展示其他内容,请随时告诉我!
感谢您的宝贵时间!
【问题讨论】:
-
你的链接是
about:blank#blocked
标签: ruby-on-rails rich-text-editor trix