How do I produce an external URL as part of a replace_html call in Ruby on Rails?

Posted by vlasits on Stack Overflow See other posts from Stack Overflow or by vlasits
Published on 2010-05-21T18:01:49Z Indexed on 2010/05/21 21:50 UTC
Read the original article Hit count: 169

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 

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about concatenation