내 Ruby on Rails 앱에서 markdown에 ruby를 사용할 수 있습니까? RedCarpet gem을 사용하고 있으며 응용 프로그램 컨트롤러에 다음과 같은 항목이 있습니다. 여기 루비를 마크 다운으로 렌더링 할 수 있습니까? Ruby on Rails 앱
class ApplicationController < ActionController::Base
before_filter :get_contact_info
private
def get_contact_info
@contact = Contact.last
end
end
그래서 내가 함께 작업 할 수있는 연락처 정보가
create_table "contacts", :force => true do |t|
t.string "phone"
t.string "email"
t.string "facebook"
t.string "twitter"
end
, 내가 <퍼센트 = @ contact.phone %를 렌더링하기 위해 가격 인하 렌더러를 알 수있는 방법이 연락의 스키마입니다 > 대신 일반 텍스트 대신 @ contact.phone 값을 사용 하시겠습니까? 아니면 다른 것을 사용해야할까요?
편집 1 : 여기
렌더링 인하 :
응용 프로그램/헬퍼/application_helper.rb
def markdown(text)
options = [:hard_wrap, :filter_html, :autolink, :no_intraemphasis]
Redcarpet.new(text, *options).to_html.html_safe
end
응용 프로그램/뷰/사이트/show.html.erb
<%= markdown(site.description) %>
편집 2 :
여기 내 해결책이었습니다. 감사합니다. 내 마크 업 도우미에 코드를 통합했는데, 지금까지 작동하는 것처럼 보였다.
def markdown(text)
erbified = ERB.new(text.html_safe).result(binding)
options = [:hard_wrap, :filter_html, :autolink, :no_intraemphasis]
Redcarpet.new(erbified, *options).to_html.html_safe
end
마크 다운을 어떻게 렌더링합니까? –
@Sergio Tulentsev 약간의 정보를 가지고 편집했는데, 더 많은 정보가 필요하면 알려주세요. 감사! – ruevaughn