【问题标题】:Rails print ruby string in haml codeRails 在 haml 代码中打印 ruby​​ 字符串
【发布时间】:2013-09-05 20:39:04
【问题描述】:

嘿,我是网络编程的新手,所以请原谅我的无知。 我在 .html.haml 视图文件中有以下代码。

%video{:controls => "controls", :height => "240", :width => "320"}
  %source{:src => @video_resource.file_path, :type => "video/mp4"}/
  %source{:src => @video_resource.file_path, :type => "video/webm"}/
  %source{:src => @video_resource.file_path, :type => "video/ogg"}/
  %object{:data => "flashmediaelement.swf", :height => "240", :type => "application/x-shockwave-flash", :width => "320"}
    %param{:name => "movie", :value => "flashmediaelement.swf"}/
    %param{:name => "flashvars", :value => "controls=true&file=movie.url"}/
  = t('html5_video_error')

如何将@video_resource.file_path 放入flashvars 对象参数文件变量(当前设置为movie.url)。我可能误解了它的工作方式。

【问题讨论】:

  • :value => "controls=true&file=#{@video_resource.file_path}" 应该这样做

标签: html ruby-on-rails flash haml


【解决方案1】:

这里需要的是基本的字符串插值,ruby on rails 语法如下:

# haml code:
%span= "I am a #{ 'interpolated' } string"
# will render:
<span>I am a interpolated string</span>

在你的情况下:

%param{:name => "flashvars", :value => "controls=true&file=#{@video_resource.file_path}"}
                                                           ^^                         ^

【讨论】:

  • 这就是我想要的。我想在我的输入中打印带有“END\n”的字符串字符作为占位符,所以它是placeholder: "eg. #{'END\n'}"}
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-27
  • 2011-08-22
  • 1970-01-01
相关资源
最近更新 更多