Skip to content

Instantly share code, notes, and snippets.

@lachlanjc
Last active August 29, 2015 14:10
Show Gist options
  • Save lachlanjc/a76d869a7fc536244eb6 to your computer and use it in GitHub Desktop.
Save lachlanjc/a76d869a7fc536244eb6 to your computer and use it in GitHub Desktop.
Render public/ Markdown files into Rails views (great for Terms of Service).
def md_file(name)
file_contents = File.open(Rails.root + 'public/' + name.to_s).read
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, underline: true, space_after_headers: true, strikethrough: true)
return markdown.render(file_contents).html_safe
end
@lachlanjc
Copy link
Author

In your view (assuming redcarpet is installed):

<%= md_file('file.md') %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment