Hi all,
I just installed the Twitter gem and created a partial where I can publish my 
latest tweets. Because the output
is plain text I created an application helper which should replace the hash 
tags into some links.

First of all is this a convenient way or is there even a better solution like 
build in link to helper or something like that (couldn't find anything so far).

My second question is regards my helper function. I had a solution which was 
working but the code sucked:


def change_hashes
 hashes = text.scan(/#\d*\w*/)
    hashes.each do |hash|
      text = sanitize(text.gsub(hash, link_to(hash, 
"https://twitter.com/#!/search/#{hash.sub(/#/, "%23")}")))
    end
    return text
end

So I refactored it into this:

def change_hashes(text)
    text.gsub(/#\d*\w*/) { |s| text.sub(s, link_to(s, 
"https://twitter.com/#!/search/#{s.sub(/#/, "%23")}")) }
  end

The problem is that if I the tweet contains more than one hash the whole tweet 
is being duplicated. Maybe someone can pinpoint me into the right direction?


Cheers
Greg

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to