【问题标题】:ERB code is breaking the lines of code after itERB 代码正在破坏它之后的代码行
【发布时间】:2013-12-19 20:03:05
【问题描述】:

我在 show.html.erb 文件中使用了以下代码来加载 youtube 视频。视频已加载,但此后的任何代码均未执行。

<p>
<iframe id="ytplayer" type="text/html" width="640" height="390"
  src="http://www.youtube.com/embed/<%=@video.youtubeid%>"
  frameborder="0"/>
</p>

【问题讨论】:

  • 日志中是否有任何错误?

标签: ruby-on-rails erb


【解决方案1】:

改成

<p>
  <iframe id="ytplayer" type="text/html" width="640" height="390"
    src="http://www.youtube.com/embed/<%=@video.youtubeid%>"
    frameborder="0">
  </iframe>
</p>

参考this post

【讨论】:

  • 这里的关键是&lt;/iframe&gt;
【解决方案2】:

您应该能够使用&lt;%= 'no line break' -%&gt; 语法,如下所示:

<iframe id="ytplayer" type="text/html" width="640" height="390"
src="http://www.youtube.com/embed/<%= @video.youtubeid -%>"
frameborder="0">
</iframe>

注意末尾的额外破折号-%&gt;

【讨论】:

  • 只有在结束 ERB 标记后面有实际空格时才会有所不同。这不是这里的情况。
猜你喜欢
  • 2015-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-14
  • 1970-01-01
  • 1970-01-01
  • 2011-02-28
  • 1970-01-01
相关资源
最近更新 更多