Basically, I am attempting to render an external website (the url of which is stored in the database) into a page in my Ruby on Rails app.
I have a field in my model 'search' called 'search' that contains web addresses with the for开发者_JS百科m 'www.example.com' or 'example.com'. I am trying to use a link_to_function call with replace_html to replace the 'maincontent' div with an iframe tag using the value of 'search' in the current instance as the src for the tag.
My current attempt is the very ugly code below. I'd be grateful for either of the following types of responses:
- How can I rewrite the concatenation string to work correctly?
- How can I get the same effect (replacing the current content of the "mainContent" div with an iframe tag using a different method?
(I had to modify the code before to remove the <> from the iframe)
link_to_function h(search.title) do |page|
page.replace_html 'mainContent', 'iframe id="embedded" src="http://" + #{search.search} />'
end
In ruby,
#{variable}
is interpolated if it's contained within double quotes."<iframe id='embedded' src='http://#{search.search}' />" # Will expand to: "<iframe id='embedded' src='http://www.example.com' />"
What's happening at the moment? Are you getting an empty
iframe
?
精彩评论