Rails以haml代码打印ruby字符串

时间:2013-09-05 20:39:04

标签: html ruby-on-rails flash haml

嘿,我对网络编程比较陌生,所以请原谅我的无知。 我在.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对象param文件变量中(目前设置为movie.url)。我可能误解了它的工作方式。

1 个答案:

答案 0 :(得分: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}"}
                                                           ^^                         ^