简体   繁体   中英

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?

像这样:

<%= @variable %>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM