使用ActionText在Rails 5.2中显示现有内容 [英] Displaying existing content in Rails 5.2 with ActionText

查看:170
本文介绍了使用ActionText在Rails 5.2中显示现有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于旧的trix编辑器/gem不再起作用,因此我已将我的应用程序升级到5.2并倾向于使用ActionText. 现在,新帖子将显示其描述",但是如何使用新安装的ActionText显示旧帖子的描述?

I have upgraded my app to rails 5.2 and inclined to use ActionText since old trix-editor/gem is no longer working. Now new posts display their "descriptions" but how can I display my old posts' DESCRIPTIONS with the new installed ActionText?

post.rb has_rich_text :description

posts_controller.rb ...params.require(:post).permit(:description)

posts_controller.rb ...params.require(:post).permit(:description)

_form.html.erb <%= f.rich_text_area :description %>

_form.html.erb <%= f.rich_text_area :description %>

show.html.erb <%= @post.description %>

show.html.erb <%= @post.description %>

描述仅从ActionText中的新记录中获取,而不从旧帖子的现有描述"列中显示

Descriptions are only fetching from new records in ActionText but not displaying from existing "description" columns for old posts

推荐答案

我遇到了类似的问题,但是在rails仓库或任何地方都找不到干净的解决方案.作为一种解决方法,您可以尝试:

I had a similar issue and I couldn't find a clean solution in the rails repo or anywhere. As a workaround, in your case, I would try:

show.html.erb:.
<%= @post.try(:description).body || @post[:description] %>

show.html.erb: .
<%= @post.try(:description).body || @post[:description] %>

那不能解决问题,但是可以帮助您填充旧的帖子值.

That wont solve the issue, but it would help you to populate old post values.

这篇关于使用ActionText在Rails 5.2中显示现有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆