0

I want to convert urls in a string to workable urls. For example: str = "Hello, this is the link for yahoo: http://www.yahoo.com"

//in the view i have
<%= parse_description(r[:description]) %>

//in helper, i am splitting each word in the string and verifying if i have a string which
//  contains http, if http is present then i am using link_to to make it a valid url:
def parse_description(str)
  s = ""
    str.split.each do |w|
       a =  w.include?("http") ? (link_to nil,"#{w}") : w
       s += "#{a} "
    end 
end

once the string is returned back to the view, the link is not clickable. what wrong i am doing?

4
  • Well, what is the value returned? How might that (along with how it is used) make a difference? Inspect the generated HTML for ideas. Commented Oct 27, 2012 at 23:11
  • basically it just returns the string that i am sending, but i want the yahoo link to be a valid url on the view. Commented Oct 27, 2012 at 23:16
  • And how do you make a link in HTML? Commented Oct 27, 2012 at 23:22
  • @Kumar So, back to my comment: "Inspect the generated HTML for ideas" Commented Oct 27, 2012 at 23:26

2 Answers 2

1

Thanks pst for your help.. while returning i just did s.html_safe.. it worked.

Sign up to request clarification or add additional context in comments.

Comments

0

To match the URI's in a String use the following code:

html_string.scan(URI.regexp) do |*matches|
  p $&
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.