Created
July 6, 2020 02:48
-
-
Save apavlyut/474f89795408e82549a44829e9a7bdba to your computer and use it in GitHub Desktop.
ActionText render for API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h3 = post.title | |
= raw post.content |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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