简体   繁体   中英

How to store a string in ruby syntax

<iframe src='xxx/ipx.php?affid=<%= val_1 %>'></iframe>

Above I frame that I store in my table. but when I fetch in view then it display like below in page source. I want to display my value of val_1

 <iframe src='xxx/ipx.php?affid=<%= val_1 %>'></iframe>

val_1 = 1

but it's not display in page source. I write in my view

<%= raw(iframe_link) %>

What's the problem. Please Help me.

Thanks In Advance

您是否尝试过html_safe?

<iframe src='xxx/ipx.php?affid=<%= val_1 %>'.html_safe></iframe>

I'm going to make several assumptions here since it wasn't fully outlined in the question but here we go.

Assuming you're creating your iframe_link in your controllers action, you should have something looking like this:

def <action>
  #some code
  iframe_link =  <iframe src='xxx/ipx.php?affid=<%= val_1 %>'></iframe>
  render something
end

First off I'm not sure how you're not getting an error there since you're attempting to create a variable from an unclosed line. If you want that to be a string you're going to want

iframe_link = "<iframe src='xxx/ipx.php?affid=<%= val_1 %>'></iframe>"

That's step one. Step two is you're going to want to make it an instance variable

@iframe_link = "<iframe src='xxx/ipx.php?affid=<%= val_1 %>'></iframe>"

Step three is you're going to want to tell the website that the string is HTML safe:

@iframe_link = "<iframe src='xxx/ipx.php?affid=<%= val_1 %>'></iframe>".html_safe

Now comes another assumption. You're wanting to access a variable called val_1 in your iframe string link. Well if you're building your iframe string link in your controller, why not simply build the variable in with the string? thus you'd have this:

@iframe_link = "<iframe src='xxx/ipx.php?affid=#{val_1}'></iframe>".html_safe

Now you'll have a string that will turn into an iframe in your view with the appropriate variable displayed in the right location when you call

<%= raw(@iframe_link %>

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