UserMailer에 이메일 본문으로 전달할 문자열을 구성하려고합니다.
다음은 코드입니다.
html_text = ""
topic_object.title = "Example title"
topic_object.body = "Example body"
html_text << 'Visit the page by <a href="http://localhost.com/topic_digests/#{topic_object.slug}>" clicking here</a>.<br>'
html_text << topic_object.title
html_text << topic_object.body
이메일을 전달하기위한이 줄이 있습니다.
UserMailer.dynamic_actual_digest(current_user.email, html_text).deliver
내 문제는 clicking here
필요한 URL로 텍스트 하이퍼 링크를 제대로 가져올 수 없다는 것입니다. 렌더링하지 않습니다. 나는 link_to를 시도하고 큰 따옴표를 시도하고 시도했습니다 <%= topic_object.slug %>
.
문제는 link_to
방법이나 a
html 태그를 사용하더라도 같은 줄에 큰 따옴표와 작은 따옴표가 모두 필요하다는 것입니다 .
내가 무엇을 놓치고 있습니까?
%Q
구문을 사용하여 문자열 생성 :
html_text = ""
topic_object.title = "Example title"
topic_object.body = "Example body"
html_text << %Q|Visit the page by <a href="http://localhost.com/topic_digests/#{topic_object.slug}>" clicking here</a>.<br>|
html_text << topic_object.title
html_text << topic_object.body
UserMailer.dynamic_actual_digest(current_user.email, html_text).deliver
html_safe
내부 에 지시문을 사용하여 명시 적 html을 보내 십시오 user_mailer.rb
.
def dynamic_actual_digest(email, html_text)
mail(to: email) do |format|
format.html { render html: html_text.html_safe }
end
end
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다