A.Ho
A.Ho

Reputation: 27

How can <p> display a variable

Is there any way that I can load a variable in a 'p' tag?

In my test.html.erb:

<p>"#{@variable}"</p>

And in my test_controller.rb

@variable = "Testing"

However, in the html, it displays "#{@variable}".

How should I fix it?

Upvotes: 1

Views: 7693

Answers (2)

Sebasti&#225;n Palma
Sebasti&#225;n Palma

Reputation: 33420

You need to print your code and then to interpolate it, try with:

<p><%= "#{@variable}" %></p>

Or just <p><%= @variable %></p>, depending on what you want to do, then you can interpolate your variables.

With <p>"#{@variable}"</p> you're just printing plain html, nothing is being interpreted by Ruby.

Upvotes: 2

uday
uday

Reputation: 8710

Like this:

<%= @variable %>

Upvotes: 2

Related Questions