动作文本未存储在创建上
我正在构建Rails应用程序,希望管理员能够使用ActionText创建丰富的文本内容。我已经根据手册,图像附件有效,但是丰富的文本不行,但我在当地的DB中看不到它们。怎么了,我想念什么? PS:我想要一种形式的多个动作文本,但是现在,我试图只能获得一个工作...
模型:
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 /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
I'm building Rails app where I want administrators to be able to use ActionText to create rich text contents. I've set up the app according to manual, Image attachments work, but rich texts dont, I can't see them in my local DB. What is wrong, what am I missing?
P.s.: I want multiple actiontexts in one form, but for now I'm trying to get just one working...
Model:
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
Controller POST method:
# 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
And typed params:
def course_params
params.require(:course).permit(
:name,
:annotation,
:price,
:capacity,
:image,
:what_you_learn
# :skillset,
# :process,
# :harmonogram,
# :student_assignment
)
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于有兴趣的人来说,问题是在.html.erb标记文件中,因为我在没有适当的属性演练的情况下复制了Rich_text_area标签。
更改
&lt;%= form.rich_text_area:what_you_learn,class:'form-control',name:“ artict-text”,input_html:{rows {rows:10}%&gt;
to
&lt; %= form.rich_text_area:what_you_learn,class:'form-control',input_html:{行:10}%&gt;
rich_text的内容然后不显示为'artiter-text',而是正确的内部params groams groams groams of [:what_you_learn]。
For anyone interested, the problem was in .html.erb markup file, as I copied the rich_text_area tag without proper walkthrough of its attributes.
Changed
<%= form.rich_text_area :what_you_learn, class: 'form-control', name: "article-text", input_html: { rows: 10 } %>
to
<%= form.rich_text_area :what_you_learn, class: 'form-control', input_html: { rows: 10 } %>
The content of the rich_text was then posted not as 'article-text', but properly inside params[:what_you_learn].