Ruby on rails Rails在HTML输出中将元素插入到错误的位置。语法错误?
这可能很简单,但我现在尝试解决它的时间更长了 我有一个helper方法Ruby on rails Rails在HTML输出中将元素插入到错误的位置。语法错误?,ruby-on-rails,image,markdown,redcarpet,Ruby On Rails,Image,Markdown,Redcarpet,这可能很简单,但我现在尝试解决它的时间更长了 我有一个helper方法picture(file,alt)和一个自定义的图像标记用于标记转换器 helper方法使用给定的文件和alt文本创建一个-标记。自定义红地毯渲染器使用此picture(file,alt)方法合成div.image,包括picture标记和附加标题。div.caption应位于div.image内部的-标记之后。但由于某些原因,我的红地毯渲染器将div.caption包含在-标记中 比如: ... 从视觉上看,它的工作方式
picture(file,alt)
和一个自定义的图像标记用于标记转换器
helper方法使用给定的文件和alt文本创建一个
-标记。自定义红地毯渲染器使用此picture(file,alt)
方法合成div.image,包括picture标记和附加标题。div.caption应位于div.image内部的
-标记之后。但由于某些原因,我的红地毯渲染器将div.caption包含在
-标记中
比如:
...
从视觉上看,它的工作方式是wwell,但根据W3C验证程序,它应该在外部工作
如何获取图片标签的div.caption?
此外,这是从方法输出HTML的好方法吗
application_helper.rb:
def picture(file, alt)
@html = "<picture>" +
"<!--[if IE 9]><video style='display: none;''><![endif]-->" +
"<source media='(min-width: 0px)' sizes='1280px' srcset='" + file.url + " 1280w'>" +
"<!--[if IE 9]></video><![endif]-->" +
"<img src='" + file.url + "' alt='" + alt + "'>"
"</picture>"
@html.html_safe
end
def图片(文件,alt)
@html=”“+
"" +
"" +
"" +
""
""
@html.html_安全
结束
定制红地毯.rb:
require 'redcarpet'
class CustomRedcarpet < Redcarpet::Render::HTML
include ApplicationHelper
# Custom Image tag like ![id](filename)
def image(link, title, alt_text)
# Use alt_text for record id
# if you don't find anything return nothing: ""
if Part.exists?(link)
@part = Part.find(link)
@file = @part.file
@caption = @part.description
@html = "<div class='project-body-image'>" +
picture(@file, @caption) +
"<div class='caption'>" + @caption + "</div>" +
"</div>"
@html.html_safe
else
nil
end
end
end
需要“红地毯”
类customRed地毯
您在此行末尾缺少了+
:
"<img src='" + file.url + "' alt='" + alt + "'>"
"<img src='" + file.url + "' alt='" + alt + "'>"
@html = <<-EOS
<picture>
<!--[if IE 9]><video style='display: none;''><![endif]-->
<source media='(min-width: 0px)' sizes='1280px' srcset='#{file.url} 1280w'>
<!--[if IE 9]></video><![endif]-->
<img src='#{file.url}' alt='#{alt}'>"
"</picture>"
@html.html_safe