plasma
plasma

Reputation: 59

Rails print ruby string in haml code

Hey I am fairly new to web programming, so please excuse my ignorance. I have the following code in a .html.haml view file.

%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')

How do I get @video_resource.file_path into the flashvars object param file variable (currently it is set to movie.url). I may be misunderstanding the way this works.

Upvotes: 1

Views: 1656

Answers (1)

MrYoshiji
MrYoshiji

Reputation: 54902

What you need here is basic string interpolation, the ruby on rails syntax is the following:

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

In your case:

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

Upvotes: 3

Related Questions