views:

67

answers:

1

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 form '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:

  1. How can I rewrite the concatenation string to work correctly?
  2. 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 
A: 
  1. 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' />"
    
  2. What's happening at the moment? Are you getting an empty iframe?

nfm
Yes, exactly... an empty frame.
vlasits
That was it. Working correctly with those changes.
vlasits
I'd vote you up but I don't have enough points. :(
vlasits
If you accept nfm's answer, s/he gets +15 (and you get +2).
John at CashCommons