动作文本未存储在创建上

发布于 2025-02-02 00:25:53 字数 1603 浏览 4 评论 0原文

我正在构建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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-黛色若梦 2025-02-09 00:25:53

对于有兴趣的人来说,问题是在.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].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文