我正在构建Rails应用程序,希望管理员能够使用ActionText创建丰富的文本内容。我已经设置了应用程序根据手册,图像附件工作,但丰富的文本不,我看不到他们在我的本地数据库。怎么了,我错过了什么?P.s.:我想要一种形式的多个行动文本,但就目前而言,我只想让其中一个工作.
型号:
class Course < ApplicationRecord
has_and_belongs_to_many :admins, join_table: 'courses_admins', class_name: 'Admin'
has_many :lessons
has_many :course_runs
has_many :course_interests
has_rich_text :what_you_learn
# has_rich_text :skillset
# has_rich_text :process
# has_rich_text :harmonogram
# has_rich_text :student_assignment
has_one_attached :image
end控制器POST方法:
# POST /courses or /courses.json
def create
@course = Course.new(course_params)
@course.image.attach(course_params[:image])
respond_to do |format|
if @course.save
format.html { redirect_to course_url(@course), notice: "Course was successfully created." }
format.json { render :show, status: :created, location: @course }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @course.errors, status: :unprocessable_entity }
end
end
end和打字的对词:
def course_params
params.require(:course).permit(
:name,
:annotation,
:price,
:capacity,
:image,
:what_you_learn
# :skillset,
# :process,
# :harmonogram,
# :student_assignment
)
end发布于 2022-05-31 09:38:20
对感兴趣的人来说,问题是在.html.erb标记文件中,因为我复制了rich_text_area标记,而没有对其属性进行适当的演练。
变化
<%= form.rich_text_area :what_you_learn, class: 'form-control', name: "article-text", input_html: { rows: 10 } %>
至
<%= form.rich_text_area :what_you_learn, class: 'form-control', input_html: { rows: 10 } %>
然后,rich_text的内容不是以“文章文本”的形式发布的,而是正确地在params:what_you_learn内部发布的。
https://stackoverflow.com/questions/72403056
复制相似问题