在我的图式中,我有:t.string "description"
在我的模型中,我有:has_rich_text :description
在我的活动建议表中,我有:
<%= f.text_area :description, placeholder: 'Enter the description of the event here', label: "Tell us about the event.", :class => "tinymce" %>
在控制器的复制方法中,我有:
def duplicate
original_event = Event.friendly.find(params[:id])
@event = original_event.dup
@event.name = original_event.name += " (copy)"
@event.slug = original_event.slug
@event.description = original_event.description
@event.address = original_event.address
@event.event_frequency = original_event.event_frequency
@event.event_types = original_event.event_types
@event.event_start_date = original_event.event_start_date
@event.event_end_date = original_event.event_end_date
@event.dance_styles = original_event.dance_styles
@event.website_url = original_event.website_url
@event.facebook_url = original_event.facebook_url
@event.instagram_url = original_event.instagram_url
@event.ticket_url = original_event.ticket_url
@event.artists = original_event.artists
render "suggest_event"
end
我也尝试过不同的变化,但没有运气:
@event.description.body = original_event.description.dup
@event.description_rich_text = original_event.description_rich_text.dup
@event.description = original_event.description.to_s
在我的rails控制台中,当我显示事件描述时,我得到了以下内容:
3.0.2 :004 > e.description
ActionText::RichText Load (0.5ms) SELECT "action_text_rich_texts".* FROM "action_text_rich_texts" WHERE "action_text_rich_texts"."record_id" = $1 AND "action_text_rich_texts"."record_type" = $2 AND "action_text_rich_texts"."name" = $3 LIMIT $4 [["record_id", 21], ["record_type", "Event"], ["name", "description"], ["LIMIT", 1]]
Rendered /Users/ogarocious/.rvm/gems/ruby-3.0.2/gems/actiontext-7.0.4/app/views/action_text/contents/_content.html.erb within layouts/action_text/contents/_content (Duration: 5.5ms | Allocations: 2229)
=>
#<ActionText::RichText:0x00007fa41c340a68
id: 28,
name: "description",
body: #<ActionText::Content "<div class=\"trix-conte...">,
record_type: "Event",
record_id: 21,
created_at: Mon, 20 Feb 2023 02:27:52.500765000 UTC +00:00,
updated_at: Tue, 21 Feb 2023 19:49:38.187025000 UTC +00:00>
当我检查描述元素时,我得到:
<body id="tinymce" class="mce-content-body vsc-initialized" data-id="event_description" aria-label="Rich Text Area. Press ALT-0 for help." contenteditable="true" spellcheck="false" data-new-gr-c-s-check-loaded="14.1097.0" data-gr-ext-installed=""><div class="trix-content"><div class="trix-content">Awesome Fusion Event in Medellin</div></div></body>
事件描述/富文本/操作文本/trix内容是否缺少需要指出的内容?
我还使用tinymce编辑器进行富文本格式设置,显示文本,这些文本一直工作良好,用于创建编辑和显示描述,只是遇到了事件复制的障碍,其他一切都复制得很好。
先谢了!
2条答案
按热度按时间lpwwtiir1#
你试过
.dup
了吗?也许会有帮助unftdfkk2#
答案是从我的事件表中删除描述列,因为描述也用于连接到事件表的ActionText富文本表。
一旦我这样做了,我就能够在我的事件控制器的复制方法中成功地用
event.description = original_event.description.body.dup
复制描述。