0

Should be a simple question, but I'm a Rails novice and just kinda hacking this together. What's the format to add in a variable to this syntax? Pseudocode:

 $var = '<html>' . $var2 . '</html>';

Except in ruby...

class PdfController < ApplicationController

  def index
    @html = %Q{
      <html>
      VARIABLE
      </html>
    }
  end
end

1 Answer 1

3

You can use Ruby interpolation:

class PdfController < ApplicationController

  def index
    @html = %Q{
      <html>
      #{ VARIABLE }
      </html>
    }
  end
end
Sign up to request clarification or add additional context in comments.

1 Comment

It's worth nothing that any valid Ruby expression can go in the interpolation braces, not just variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.