Skip to content

Instantly share code, notes, and snippets.

@apavlyut
Created July 6, 2020 02:48
Show Gist options
  • Save apavlyut/474f89795408e82549a44829e9a7bdba to your computer and use it in GitHub Desktop.
Save apavlyut/474f89795408e82549a44829e9a7bdba to your computer and use it in GitHub Desktop.
ActionText render for API
h3 = post.title
= raw post.content
class Post < ApplicationRecord
has_rich_text :content
def as_json(options = {})
add_opts = {
key: "post-#{id}",
content: content_html.gsub('action-text-attachment','div').html_safe,
published: created_at.strftime("%d.%m.%y"),
}
super(options).merge(add_opts)
end
def content_html
Web::PostsController.new.render_to_string(
partial: "web/posts/post",
locals: {
post: self,
}
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment